Api Utilities
When working frontend/backend and working with api's, I like to map the responses to classes so that I get nice type completion. and so I can add additional
helper methods on said classes, related to what they do.
We use :
Documentation:
https://api-utilities.idt.dev
Preview
Please refer to the documentation above to learn about how api-utilities works.
Here's a little sample code as a teaser :D
import {Api, DataTransferObject} from "api-utilities";
const api = Api.create({
baseUrl : 'your apis base url, for ex: https://my.api.com',
headers : {
'Content-Type' : 'application/json',
'Accept' : 'application/json',
}
})
api.setAuthorizationToken('jwt');
export default class UserModel extends DataTransferObject<UserModel> {
public id: number;
public username: string;
}
UserModel.create({username : 'Bruce', id : 1});
const response = await api.asOne(UserModel).get('/api/user/me');
const user = response.get();
We also have "Forms" to make frontend a little more fun.
const userForm = api.form(UserModel, RequestMethod.PATCH, '/api/user/me');
userForm.username = 'Setting a new username with type safety! :D';
await userForm.submit();