@sofiakb/resto
v1.0.6
Published
A typescript library for axios API calls.
Downloads
15
Readme
About The Library
The library simplify API calls with axios library.
Built With
Prerequisites
- axios
- typescript
Installation
npm install --save @sofiakb/resto
Usage
example.api.ts
import { Api } from "@sofiakb/resto";
export class ExampleApi extends Api {
server = 'https://httpbin.org/status';
}
example.controller.ts
import { HttpController } from "@sofiakb/resto";
import Example from './example';
import ExampleService from './example.service';
export default class ExampleController extends HttpController<Example> {
service: ExampleService;
constructor() {
super({ service: new ExampleService() });
}
get405() {
return this.service.get405();
}
get404() {
return this.service.get404();
}
get200() {
return this.service.get200();
}
}
example.service.ts
import { HttpService } from "@sofiakb/resto";
import Example from './example';
import { ExampleApi } from './example.api';
export default class ExampleService extends HttpService<Example> {
constructor() {
super({ api: ExampleApi, model: Example });
}
get405() {
return this.httpApi.get('405');
}
get404() {
return this.httpApi.get('404');
}
get200(): Promise<Record<string, unknown>> {
return this.httpApi.get('200', { cast: false }) as Promise<Record<string, unknown>>;
}
}
example.ts
import { Model, ModelAttribute } from "@sofiakb/resto";
export default class Example extends Model {
id: string;
static icon = {
name: 'test',
type: 'la',
};
constructor(attributes?: any) {
super({
attributes: [ModelAttribute.create('id')],
casts: {
created: 'date',
updated: 'date',
},
table: '/',
});
this.__setItemAttributes(attributes);
}
static create(properties?: any) {
return new Example(properties);
}
}
Roadmap
See the open issues for a list of proposed features (and known issues).
License
Distributed under the MIT License. See LICENSE
for more information.