NodeExamples

a bunch of node.js examples

tigoe.github.io
Home

This project is maintained by tigoe

tigoe-node-fetch-client

This example shows how to use node.js to make requests to a RESTful API and simplify the result and serve it as a RESTful API. It assumes you’re using a microcontroller-based client or have some other reason for needing the results of an API to be simplified.

The calling client can change any of the properties of the query string and they’ll be replaced.

The app makes a call to NOAA’s Tides and Currents API. Defaults to NYC Battery Station. See the URL Builder and this link for details. The return from the NOAA site looks like this:

{"metadata":{"id":"8518750","name":"The Battery","lat":"40.7006","lon":"-74.0142"},"data":[{"t":"2023-01-09 10:48", "v":"0.752", "s":"0.027", "f":"1,0,0,0", "q":"p"}]}

The summarized version from this app looks like this:

{"time":"2023-01-09 21:24","waterLevel":"0.536"}

This same approach could be adapted to any complex RESTful API. If goes like this: