@jojoxd/http-client
A Simple HTTP Client using ky and TsED json-mapper
Installation
yarn install @jojoxd/http-client
Usage
Standalone and Browser
import { HttpClient } from '@jojoxd/http-client';
const client = new HttpClient();
const response = await client.get('https://example.org/');
TsED
NOTE: This requires
@tsed/di
to be installed.
// Server.ts
import '@jojoxd/http-client/tsed';
@Configuration(...)
export class Server {}
// Service.ts
import { Service, Inject } from '@tsed/common';
import { HttpClient } from '@jojoxd/http-client';
@Service()
class Service
{
@Inject()
protected readonly client!: HttpClient;
async doSomething(): Promise<void>
{
await this.client.get('https://example.org');
}
}
Vue
// main.ts
import { createApp } from 'vue';
import { createHttpClient } from '@jojoxd/http-client/vue';
const app = createApp(RootComponent);
app.use(createHttpClient(/* Options */));
// Component, Composition function etc.
import { HttpClient } from '@jojoxd/http-client/vue';
import { inject } from 'vue';
function composedFunction()
{
const client = inject(HttpClient);
client.get('https://example.org/').then((data) => {});
}