@nexst/client
v0.0.62
Published
⚡ next + nest ⚡
Downloads
4
Maintainers
Readme
HttpClient
It uses axios internally, methods are listed here:
get(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse>
post(url: string, data?: any, config?: AxiosRequestConfig): Promise<AxiosResponse>
update(url: string, data?: any, config?: AxiosRequestConfig): Promise<AxiosResponse>
delete(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse>
Basic usage:
import React from 'react';
export default class extends React.Component {
private client: HttpClient;
componentDidMount() {
const baseURL: string = `${process.env.HOST}:${process.env.PORT}`;
this.client = new HttpClient(baseURL);
}
}
If we have token like JWT
(Json Web Token) and logged in, usage is like below:
import React from 'react';
export default class extends React.Component {
private client: HttpClient;
static getInitialProps({ req }) {
return {
user: req.user,
};
}
componentDidMount() {
const baseURL: string = `${process.env.HOST}:${process.env.PORT}`;
const token: string = this.props.user.token;
this.client = new HttpClient(baseURL, token);
}
}