@sofiakb/resto
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

Contributors Forks Stargazers Issues MIT License


resto

A typescript library for http API calls.


Report Bug · Request Feature

Table of Contents
  1. About the library
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgements

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @sofiakb/resto

Weekly Downloads

1

Version

1.0.6

License

MIT

Unpacked Size

99.2 kB

Total Files

66

Last publish

Collaborators

  • sofiakb