decorator-http-template

前后端通用的网络请求注解插件

APACHE-2.0 License

Downloads
11
Stars
7
Committers
1

npm install @canyuegongzi/decorator-http-template

nest angular HttpPost() post HttpHeader() json HttpResponseType() json HttpBaseUrl() HttpPostData() post HttpRes()


class TestHeader {
      @HttpHeader('Content-Type: application/json')
      @HttpBaseUrl('http://127.0.0.1:3000')
      @HttpPost('/login')
      @HttpResponseType('json')
      public async test(@HttpPostData('username') postData, @HttpRes() res?) {
          //  res  AxiosResponse res.data  
          //  res
          console.log(res);
          return res.data;
      }
}

const testInstance = new TestHeader()
const res = await testInstance.test({username: 'userName1', password: 123456});

  1. Response

API

  • HttpHeader(headers: string | string[])
 HttpHeader 
  • HttpPost(url: string, data?: object, options?: string[])
HttpPost  post   HttpPostData 
  • HttpGet(url: string, data?: any, options?: string[])
HttpGet  get   HttpParams
  • HttpDelete(url: string, data?: any, options?: string[])
HttpDelete  delete  
  • HttpOptions(url: string, data?: any, options?: string[])
HttpGet  options 
  • HttpPatch(url: string, data?: any, options?: string[])
HttpGet  patch 
  • HttpTransformRequest(transformRequest: (data: any) => any)
HttpTransformRequest 
  • HttpBaseUrl(baseUrl: string)
HttpBaseUrl 
  • HttpResponseType(type?: ResponseType)
HttpResponseType  arraybuffer | blob | document | json | text |stream

  • HttpQuery(key?: string)
HttpQuery 
  • HttpParams(key?: string)
HttpParams 
  • HttpPostData(key?: string)
HttpPostData  post 
  • HttpRes()
HttpRes  AxiosResponse