HTTP POST Requests in Solidity
In addition to HTTP GET, the Witnet Web Oracle also gives your smart contracts the ability to perform POST queries with full data integrity thanks to its multi-layered decentralization model.
This is best suited for pieces of data that are available on multiple APIs, because many of them can be queried at once and aggregated together, thus getting an increased level of decentralization and fault tolerance.
The process of defining and performing HTTP POST requests in Solidity using the Witnet oracle is very similar to that of HTTP GET requests. Please make sure that you are familiar with how that works:
The only difference exists when specifying the data sources. Here is an example of an HTTP POST data source:
const testPostSource = new Witnet.HttpPostSource(
"This is the request body",
This little example queries an HTTPBin API that echoes back any data and headers that you send in your POST requests. In this data source, we are sending some special header through HTTP POST, and then parsing the same header from the result that we get from the API.
These are the arguments of
- 1.URL to query, as a String
- 2.Request body (aka data), as a String (optional)