Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@interaction/http-function

Package Overview
Dependencies
Maintainers
4
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@interaction/http-function

使用的类必须注入HttpClient,如

  • 0.0.7
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
4
Weekly downloads
 
Created
Source

快速上手(HttpFunction)

前提

使用的类必须注入HttpClient,如

constructor(

​ public http: HttpClient

) { }

介绍

1、主要包括五种请求方式:
方法名参数(请情见下表)返回数据格式
GETurl: string,
code: string = '1000000'
errMsg: string = null
code: "1000000"
message: "SUCCESS"
data: {}
GET_DATAurl: string,
code: string = '1000000'
errMsg: string = null
data: {}
POSTurl: string,
code: string = '1000000'
errMsg: string = null
code: "1000000"
message: "SUCCESS"
data: {}
DELETEurl: string,
code: string = '1000000'
errMsg: string = null
code: "1000000"
message: "SUCCESS"
data: {}
PATCHurl: string,
code: string = '1000000'
errMsg: string = null
code: "1000000"
message: "SUCCESS"
data: {}
PUTurl: string,
code: string = '1000000'
errMsg: string = null
code: "1000000"
message: "SUCCESS"
data: {}
2、参数
参数名称是否必填参数介绍
url: string必填接口url路径
code: string非必填接口url返回的数据code,默认为'1000000'
errMsg非必填如果使用此参数,必须注入ant-reset-private的modal: ModalService(这个参数,目前只有集成在用,后期会将此参数删除)

使用

1、创建一个angular服务,并注入HttpClient
@Injectable({
  providedIn: 'root'
})
export class Service {

  constructor(
    public http: HttpClient,
  ) { }
}
2、导入GET
import { GET, POST } from '@interaction/http-function'


3、为angular服务创建一个方法
@Injectable({
  providedIn: 'root'
})
export class Service {

  constructor(
    public http: HttpClient,
  ) { }

  @GET('/getdata')
  getData(params: { params: HttpParams }): Observable<any> {
    return null;
  }

 @POST('/getdata')
  postData(params): Observable<any> {
    return null;
  }

}
4、在组件中使用
export class HomeComponent {
	constructor(
		public service: Service
   ){}

	get(): void {
	  const params: HttpParams = new HttpParams().set('id', `${id}`);
	  this.service.getData({ params: params }).subscribe(
		(sucess)=> {},
		(error) => {}
	  )
	}
	
	post(): void {
	  const params = {id: `${id}`};
	  this.service.postData(params).subscribe(
		(sucess)=> {},
		(error) => {}
	  )
	}
}

FAQs

Package last updated on 04 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc