Skip to content

A basic API endpoint written in Node.js using Express. A simple app that returns stored data in response to web requests.

License

Notifications You must be signed in to change notification settings

ElenaChes/expressjs-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API App

A basic API endpoint written in Node.js using Express.
A simple app that returns stored data in response to web requests.

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 endpoint (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 request header, body, or query parameters to limit access.
  • Add more routes as needed (may require using express.Router() and separate route files/folders).
  • Add more JSON files or store data in variables to expand your API.

Tip

For a more complete example with multiple routes, parameters, and files/folders, see my Url Shortener project.

About

A basic API endpoint written in Node.js using Express. A simple app that returns stored data in response to web requests.

Topics

Resources

License

Stars

Watchers

Forks