Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine airnode-examples http gateway integrations into one #1664

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silver-parents-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@api3/airnode-examples': minor
---

Combine http gateway integrations into a single integration
8 changes: 3 additions & 5 deletions packages/airnode-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@ reserved parameters. The following list orders integrations alphabetically:
demonstration of the [post-processing](https://docs.api3.org/ois/latest/processing.html) feature.
- [coingecko-pre-processing](https://github.com/api3dao/airnode/tree/master/packages/airnode-examples/integrations/coingecko-pre-processing) -
demonstration of the [pre-processing](https://docs.api3.org/ois/latest/processing.html) feature.
- [coingecko-signed-data](https://github.com/api3dao/airnode/tree/master/packages/airnode-examples/integrations/coingecko-signed-data) -
demonstration of signed data retrieval for beacon updates.
- [coingecko-http-gateways](https://github.com/api3dao/airnode/tree/master/packages/airnode-examples/integrations/coingecko-http-gateways) -
demonstration of the
[HTTP gateway and HTTP signed data gateway](https://docs.api3.org/airnode/latest/grp-providers/guides/build-an-airnode/http-gateways.html).
- [coingecko-template](https://github.com/api3dao/airnode/tree/master/packages/airnode-examples/integrations/coingecko-template) -
demonstration of [template](https://docs.api3.org/airnode/latest/grp-developers/using-templates.html) requests.
- [coingecko-testable](https://github.com/api3dao/airnode/tree/master/packages/airnode-examples/integrations/coingecko-testable) -
demonstration of how to test the endpoint using the
[HTTP gateway](https://docs.api3.org/airnode/latest/grp-providers/guides/build-an-airnode/http-gateways.html).
- [failing-example](https://github.com/api3dao/airnode/tree/master/packages/airnode-examples/integrations/failing-example) -
demonstration of Airnode error handling through an invalid request.
- [relay-security-schemes](https://github.com/api3dao/airnode/tree/master/packages/airnode-examples/integrations/relay-security-schemes) -
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,51 @@

This example contains the same API integration as `../coingecko`.

The only difference is that this integration allows the endpoint to return signed data that can be then submitted on
chain.
The only difference is that this integration allows the endpoint to return either unsigned or signed data via the HTTP
gateway or HTTP signed data gateway, respectively.

See the documentation for the
[signed data gateway](https://docs.api3.org/airnode/latest/grp-providers/guides/build-an-airnode/http-gateways.html#http-signed-data-gateway).
For more details, see the documentation for the
[HTTP gateways](https://docs.api3.org/airnode/latest/grp-providers/guides/build-an-airnode/http-gateways.html).

## Encode parameters
## HTTP gateway

The coingecko requests expects a parameter `coinId` which needs to be passed to the gateway encoded using
### Trigger a request

You can trigger the API call with a POST request. For example, you can use `curl` in the terminal:

```sh
curl -X POST -H 'Content-Type: application/json' -d '{"parameters": {"coinId": "bitcoin"}}' '<HTTP_GATEWAY_URL>/<ENDPOINT_ID>'
```

#### When deployed on cloud

Before making the request, you need to replace the example values:

- `<HTTP_GATEWAY_URL>` - You can find this value as part of the terminal output of the `yarn deploy-airnode` command
- `<ENDPOINT_ID>` - You can find this value in `config.json` under `triggers.rrp[0].endpointId` path

The correct command may look like this:

```sh
curl -X POST -H 'Content-Type: application/json' -d '{"parameters": {"coinId": "bitcoin"}}' 'https://x9sidy9ln0.execute-api.us-east-1.amazonaws.com/v1/d6ed7e8b-40fa-1392-3e4a-37e225ccda20/0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4'
```

#### When running Airnode locally

When Airnode is run locally, the HTTP gateway endpoint is always
`http://localhost:<PORT>/http-data/01234567-abcd-abcd-abcd-012345678abc/<ENDPOINT_ID>`.

For example:

```sh
curl -X POST -H 'Content-Type: application/json' -d '{"parameters": {"coinId": "bitcoin"}}' 'http://localhost:3000/http-data/01234567-abcd-abcd-abcd-012345678abc/0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4'
```

## HTTP signed data gateway

### Encode parameters

The coingecko endpoint expects a parameter `coinId` which needs to be passed to the signed data gateway encoded using
[Airnode ABI](https://docs.api3.org/airnode/latest/reference/specifications/airnode-abi-specifications.html).

We have encoded two basic parameter types:
Expand All @@ -22,15 +58,15 @@ We have encoded two basic parameter types:

Feel free to encode a different parameter type to make a different request.

## Trigger a request
### Trigger a request

You can trigger the API call with a POST request. For example, you can use `curl` in the terminal:

```sh
curl -X POST -H 'Content-Type: application/json' -d '{"encodedParameters": "0x3173000000000000000000000000000000000000000000000000000000000000636f696e49640000000000000000000000000000000000000000000000000000626974636f696e00000000000000000000000000000000000000000000000000"}' '<HTTP_SIGNED_DATA_GATEWAY_URL>/<ENDPOINT_ID>'
```

### When deployed on cloud
#### When deployed on cloud

Before making the request, you need to replace the following placeholders:

Expand All @@ -46,7 +82,7 @@ The correct command may look like this:
curl -X POST -H 'Content-Type: application/json' -d '{"encodedParameters": "0x3173000000000000000000000000000000000000000000000000000000000000636f696e49640000000000000000000000000000000000000000000000000000626974636f696e00000000000000000000000000000000000000000000000000"}' 'https://am6ncplkx4.execute-api.us-east-1.amazonaws.com/v1/d6ed7e8b-40fa-1392-3e4a-37e225ccda20/0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4'
```

### When running Airnode locally
#### When running Airnode locally

When Airnode is run locally, the HTTP signed data gateway endpoint is always
`http://localhost:<PORT>/http-signed-data/01234567-abcd-abcd-abcd-012345678abc/<ENDPOINT_ID>`. For now, `PORT` number is
Expand All @@ -58,7 +94,7 @@ For example:
curl -X POST -H 'Content-Type: application/json' -d '{"encodedParameters": "0x3173000000000000000000000000000000000000000000000000000000000000636f696e49640000000000000000000000000000000000000000000000000000626974636f696e00000000000000000000000000000000000000000000000000"}' 'http://localhost:3000/http-signed-data/01234567-abcd-abcd-abcd-012345678abc/0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4'
```

## Output
### Output

The example output might look like this:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
"enabled": false
},
"httpGateway": {
"enabled": false
"enabled": true,
"maxConcurrency": 20,
"corsOrigins": []
},
"httpSignedDataGateway": {
"enabled": true,
Expand All @@ -74,7 +76,13 @@
"cacheResponses": false
}
],
"http": [],
"http": [
{
"endpointId": "0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4",
"oisTitle": "CoinGecko basic request",
"endpointName": "coinMarketData"
}
],
"httpSignedData": [
{
"endpointId": "0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
enabled: false,
},
httpGateway: {
enabled: false,
enabled: true,
maxConcurrency: 20,
corsOrigins: [],
},
httpSignedDataGateway: {
enabled: true,
Expand All @@ -81,7 +83,13 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
cacheResponses: false,
},
],
http: [],
http: [
{
endpointId: '0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4',
oisTitle: 'CoinGecko basic request',
endpointName: 'coinMarketData',
},
],
httpSignedData: [
{
endpointId: '0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4',
Expand Down

This file was deleted.

Loading