0.1.20 • Published 2 years ago

api-utilities v0.1.20

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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');

// Create your DataTransferObject
export default class UserModel extends DataTransferObject<UserModel> {
	public id: number;
	public username: string;
}

// Convert your plain js object into a class:
UserModel.create({username : 'Bruce', id : 1});

// Get a "User" from your api 
const response = await api.asOne(UserModel).get('/api/user/me');
// and convert the response to a UserModel instance.
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';

// Submit the request
await userForm.submit();

// Some states:
// userForm.processing
// userForm.recentlySuccessful
// userForm.hasError('username');

//.... so much more
0.1.20

2 years ago

0.1.16

2 years ago

0.1.17

2 years ago

0.1.18

2 years ago

0.1.19

2 years ago

0.1.10

2 years ago

0.1.11

2 years ago

0.1.12

2 years ago

0.1.13

2 years ago

0.1.14

2 years ago

0.1.15

2 years ago

0.1.0

2 years ago

0.0.3

3 years ago

0.1.1

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.0.8

2 years ago

0.1.9

2 years ago

0.1.4

2 years ago

0.0.5

2 years ago

0.1.3

2 years ago

0.0.4

3 years ago

0.1.6

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.2-2

3 years ago

0.0.2-1

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago