0.0.62 • Published 5 years ago

@nexst/client v0.0.62

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

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);
  }
}
0.0.62

5 years ago

0.0.61

5 years ago

0.0.60

5 years ago

0.0.59

5 years ago

0.0.58

5 years ago

0.0.57

5 years ago

0.0.56

5 years ago

0.0.55

5 years ago

0.0.54

5 years ago

0.0.53

5 years ago

0.0.52

5 years ago

0.0.51

5 years ago

0.0.50

5 years ago