0.0.62 • Published 7 years ago

@nexst/client v0.0.62

Weekly downloads
1
License
MIT
Repository
github
Last release
7 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

7 years ago

0.0.61

7 years ago

0.0.60

7 years ago

0.0.59

7 years ago

0.0.58

7 years ago

0.0.57

7 years ago

0.0.56

7 years ago

0.0.55

7 years ago

0.0.54

7 years ago

0.0.53

7 years ago

0.0.52

7 years ago

0.0.51

7 years ago

0.0.50

7 years ago