1.0.0-dev.11 • Published 2 years ago
@sofiakb/nuxt3-http v1.0.0-dev.11
comment: <> ()
About The Library
The library simplify API calls with axios library.
Built With
Prerequisites
- axios
- typescript
Installation
npm install --save @sofiakb/nuxt3-httpUsage
example.api.ts
import { Api } from "@sofiakb/nuxt3-http";
export class ExampleApi extends Api {
	server = 'https://httpbin.org/status';
}example.controller.ts
import { HttpController } from "@sofiakb/nuxt3-http";
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/nuxt3-http";
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/nuxt3-http";
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.
1.0.0-dev.11
2 years ago
1.0.0-dev.10
3 years ago
1.0.0-dev.9
3 years ago
1.0.0-dev.8
3 years ago
1.0.0-dev.7
3 years ago
1.0.0-dev.6
3 years ago
1.0.0-dev.5
3 years ago
1.0.0-dev.4
3 years ago
1.0.0-dev.3
3 years ago
1.0.0-dev.2
3 years ago
1.0.0-dev.1
3 years ago