Skip to content

A basic API access point written in Node JS using Express, an app that sends stored data when recieving a web request.

License

Notifications You must be signed in to change notification settings

ElenaChes/Express-Js-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API app example

A basic API endpoint written in Node JS using Express.
Description: an app that sends stored data when recieving a web request.

Content


Installation

  1. Replace the mock data in data.json with your data.
  2. Run npm i.
  3. Start index.js.

Behaviour

  1. A user accesses the /api path of the app. (for example http://localhost:8080/api)
  2. The app sends the data from data.json to the user in JSON format.

Example success:

{
  "status": "success",
  "data": {
    "example data": ["some data", "some other data"],
    "different data": "also data"
  }
}

Example error:

{
  "status": "error",
  "message": "Couldn't fetch resource."
}

Usage Ideas

  • Check for a key or authentication password in the header, body or parameters of the request to limit access to the API.
  • Add more routes based on your needs. (Might need to create route handling (express.Router(), router.get) in 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 routes, parameters, files and folders feel free to check out my Url Shortener.

About

A basic API access point written in Node JS using Express, an app that sends stored data when recieving a web request.

Topics

Resources

License

Stars

Watchers

Forks