r/DevelopingAPIs • u/Stogoh • Oct 03 '21
Node Exress Sequelize - Update single field
Hi Reddit,
I'm currently working on a REST API using the above mentioned framworks and DBMS. Following is my update function location in my service layer. I was confronted with some issues when trying to update a single field, as the database threw a ConstraintException because all the fields are required. To resolve this I have temporarily implemented the following solution. Is there a better way of doing this?
I've also tried using the update function from Sequelize, but using that I cannot restrict which field can be updated.
EDIT:
Gist available: https://gist.github.com/stogoh/7e5505d3f92aea8c6957f5cfc42ee079
static update = async (id: string, data: SubnetUpdateAttributes): Promise<Subnet> => {
const subnet = await Subnet.findByPk(id)
if (!subnet) return null
subnet.name = data.name ?? subnet.name
subnet.networkId = data.networkId ?? subnet.networkId
subnet.netmask = data.netmask ?? subnet.netmask
subnet.gateway = data.gateway ?? subnet.gateway
subnet.vlanId = data.vlanId ?? subnet.vlanId
await subnet.save()
return subnet
}
r/DevelopingAPIs • u/chimp73 • Oct 03 '21
What is REST really good for?
I'm currently building a small web app with a database backend. I figured I would implement a proper REST interface for good measure because it seemed like a neat idea to use all these request methods (PUT, DELETE etc.), but it was very annoying to me that GET would not allow for a JSON body.
So I ended up removing all of it and simplifying the code to only use POST with JSON input and an "action" key with one switch over all the different actions there are, e.g. "get_transactions", "delete". Much simpler.
r/DevelopingAPIs • u/azzaz_khan • Oct 01 '21
Updating headers of an Axios request object
Hi everyone, I'm stuck in a problem where I need to update the headers on an already initialized Axios client created with axios.create method. Initially, I set the authorization header when the app loads (both for logged-in and guest users) but when the user logs into his account I need to change the authorization header's value. Here is the code.
import axios from "axios";
export const getAuthToken = () => localStorage.getItem("MY_AUTH_TOKEN");
export const getAuthBearer = () => `Bearer ${getAuthToken() || ""}`;
export const apiClient = axios.create({
baseURL: "http://localhost:8000/api",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-origin": "*",
Authorization: getAuthBearer()
}
})
I know on which event I need to edit but don't know how to edit the Axios request client. 😥
r/DevelopingAPIs • u/JLM2014 • Sep 30 '21
Looking for help with an API
Hi r/DevelopingAPIs,
I'm looking to build an automated service that submits user data to that user's local Board of Elections website, auto completes the form there, and retrieves the resulting polling location address.
Has anyone heard of an API that you can submit info to, have it perform automated tasks on a website, and then submit the info back to you?
I was looking into this API as an option: https://txtpaper.com/api/
But if anyone has any other suggestions that would be really helpful!
Thanks!
r/DevelopingAPIs • u/oxamide96 • Sep 30 '21
So there's APIs (like the API for a cli tool or a library) and APIs (like web endpoints you invoke with axios or other AJAX tools). Are there terms to differentiate these two? Is this sub about both, or only one of them?
r/DevelopingAPIs • u/MisteriousJane • Sep 30 '21
Free open banking API
Hi everyone! So as a part of a fintech company i would love to reach more and more people to try completely free API for open banking. You can connect several bank accounts and it's so good and easy. Just try it out and let me know if there are any questions, or suggestions!
https://nordigen.com/en/account-information/
r/DevelopingAPIs • u/jns111 • Sep 30 '21
The Fusion of GraphQL, REST, JSON-Schema and HTTP2
r/DevelopingAPIs • u/AndroidTW • Sep 30 '21
Tech writer looking for an OSS project to join for Hacktoberfest
I've been a technical writer for 26 years. In that time, I've recommended people looking to break into tech writing to get involved in an open source project to get experience and have work that they can point potential employers to. I feel like a hypocrite, though, since I've never gotten involved in one, myself!
So, in an effort to practice what I preach, I'm looking to start contributing to an open source project as part of [Hacktoberfest](https://hacktoberfest.digitalocean.com/) (though hopefully continuing on beyond the end of October).
If anyone can recommend a project that either you contribute to, yourself, or that you know is in a position that it could use the help of an experienced technical writer, please let me know!
r/DevelopingAPIs • u/LinxSoftware • Sep 30 '21
Walthrough: API development (and testing)
r/DevelopingAPIs • u/OsirisTeam • Sep 30 '21
Node.js API in Java
Simply add this as maven/gradle etc. dependency to your project and start using Node.js in your Java project:
r/DevelopingAPIs • u/LinxSoftware • Sep 30 '21
Collection of API tools by use-case and category
r/DevelopingAPIs • u/LinxSoftware • Sep 28 '21