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

Allow API call to be skipped in endpoints #1527

Closed
Tracked by #1605
bbenligiray opened this issue Nov 10, 2022 · 5 comments · Fixed by #1586
Closed
Tracked by #1605

Allow API call to be skipped in endpoints #1527

bbenligiray opened this issue Nov 10, 2022 · 5 comments · Fixed by #1586
Assignees
Milestone

Comments

@bbenligiray
Copy link
Member

Sometimes you want Airnode to not make an API call and just use pre/post processing (for example, to generate a pseudo-random number). Both endpointId and templateId are hashes (endpointId only by convention), which means that they should never be zero. Then, we can use zero endpointId/templateId as a signal of omitting the API call.

@metobom mentioned to me that he wanted to contribute to Airnode and this may be an easy enough task. Also, it would be nice to have this in 0.10.0. @aTeoke for visibility.

@metobom
Copy link
Member

metobom commented Nov 10, 2022

Setting endpointId to zero will cause problems in configs with multiple OIS. How about changing "operation" and "fixedOperationParameters" to optional from required in the endpoint as an indicator?

@bbenligiray bbenligiray changed the title Skip the API call if endpointId or templateId is zero Allow API call to be skipped in endpoints Nov 12, 2022
@bbenligiray
Copy link
Member Author

I and @bdrhn9 understood the above because we talked about this offline but I doubt this is clear to anyone else. So we want to be able to define an endpoint that skips the API call. If this is a regular endpoint that calls an API

{
          "name": "GET /last/stock/{symbol}",
          "operation": {
            "path": "/last/stock/{symbol}",
            "method": "get"
          },
          "parameters": [
            {
              "name": "symbol",
              "operationParameter": {
                "in": "path",
                "name": "symbol"
              }
            },
            {
              "name": "ts",
              "operationParameter": {
                "in": "query",
                "name": "ts"
              }
            }
          ],
          "reservedParameters": [
            {
              "name": "_type"
            },
            {
              "name": "_path"
            },
            {
              "name": "_times"
            }
          ],
          "fixedOperationParameters": []
        }

an endpoint that skips the API call could be

{
          "name": "GET /last/stock/{symbol}",
          "parameters": [
            {
              "name": "symbol",
              "operationParameter": {
                "in": "path",
                "name": "symbol"
              }
            },
            {
              "name": "ts",
              "operationParameter": {
                "in": "query",
                "name": "ts"
              }
            }
          ],
          "reservedParameters": [
            {
              "name": "_type"
            },
            {
              "name": "_path"
            },
            {
              "name": "_times"
            }
          ]
        }

The reasoning is that omitting the operation here implies that there is no API operation to be used, which also makes fixedOperationParameters redundant. We still need parameters because they may be used in pre/post-processing.

Another point here is that fixedOperationParameters should probably have been a field under operation as in

{
          "name": "GET /last/stock/{symbol}",
          "operation": {
            "path": "/last/stock/{symbol}",
            "method": "get",
             "fixedOperationParameters": []
          },
          "parameters": [
            {
              "name": "symbol",
              "operationParameter": {
                "in": "path",
                "name": "symbol"
              }
            },
            {
              "name": "ts",
              "operationParameter": {
                "in": "query",
                "name": "ts"
              }
            }
          ],
          "reservedParameters": [
            {
              "name": "_type"
            },
            {
              "name": "_path"
            },
            {
              "name": "_times"
            }
          ]
        }

I'm less convinced about this being an urgent enough need to be in 0.10.0 now.

@aquarat
Copy link
Contributor

aquarat commented Nov 17, 2022

I looked into this some time back. About 6 months ago axios had the ability to load data from a data URI added. An example data URI call: axios.get('data:text/vnd-example+xyz;foo=bar;base64,R0lGODdh')

More info at MDN here

@bbenligiray
Copy link
Member Author

The OIS will still need to specify that the API call is to be skipped without using axios-specific features, so I'm not sure how that helps this

@martinkolenic
Copy link
Contributor

Hi, I have successfully tested this.

Steps: Clear the endpoint and only keep the relevant entries in the preprocessingSpecifications of the coingecko-pre-processing example. Then deploy Airnode and attempt making a request. Deploy the Airnode and attempt making a request
Expected result: Successful preprocessing without making an API call
Actual result: No API call was made but it did not return a meaningful response due to a fault in my test code (the pre-processed date value could not be cast to a string type which I set there thinking it would work). Nevertheless, I consider the test to be successful as the API cal was skipped and some tasks were carried out anyway, without a hitch on Airnode's side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants