A basic API access point written in Node JS using Express.
Description: an app that sends stored data when recieving a web request.
- Replace the mock data in
data.json
with your data. - Run
npm i
. - Start
index.js
.
- A user accesses the
/api
path of the app. (for examplehttp://localhost:8080/api
) - The app sends the data from
data.json
to the user in JSON format.
- Check for a key or authentication password in the parameters of the url to limit access to the API.
- Add more paths based on your needs. (Might need to move the route handling (
router.get
) to separate files or folders) - Add more JSON files based on your needs, or store data in variables as needed.
Tip
For an example of a full API app with multiple paths, parameters, files and folders feel free to check out my Url shortener.