@namestys/http-plugin-js
v2.0.0-alpha.0
Published
HTTP plugin enabling invocating http methods through web3api
Downloads
6
Readme
HTTP Plugin
Http plugin curently supports two different methods GET
and POST
. Similar to calling axios, when defining request you need to specify a response type. Headers and query parameters may also be defined.
Response Types
TEXT
- The server will respond with text, the HTTP plugin will return the text as-is.
BINARY
- The server will respond with binary data (ArrayBuffer), the HTTP plugin will encode as a base64 string and return it.
GET request
Below is sample invocation of the GET
request with custom request headers and query parameters (urlParams
).
const response = await web3ApiClient.query<{ get: Response }>({
uri: new Uri("w3://ens/http.web3api.eth"),
query: `
query {
get(
url: "http://www.example.com/api"
request: {
responseType: TEXT
urlParams: [{key: "query", value: "foo"}]
headers: [{key: "X-Request-Header", value: "req-foo"}]
}
)
}
`
})
POST request
Below is sample invocation of the POST
request with custom request headers and query parameters (urlParams
). It is also possible to set request body as shown below.
const response = await web3ApiClient.query<{ get: Response }>({
uri: new Uri("w3://ens/http.web3api.eth"),
query: `
mutation {
post(
url: "http://www.example.com/api"
request: {
responseType: TEXT
urlParams: [{key: "query", value: "foo"}]
headers: [{key: "X-Request-Header", value: "req-foo"}]
body: "{data: 'test-request'}"
}
)
}
`
})