Skip to content

MichaelCurrin/express-rest-quickstart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Express JS REST Quickstart

A base REST API project using Express and Node

GitHub tag License

Package - express

Requirements

Installation

Install system dependencies

Install Node.js using this gist.

Clone project

Clone repo.

$ git clone git@github.com:MichaelCurrin/express-rest-quickstart.git
$ cd express-js-create-app-quickstart

Install project dependencies

npm install

Usage

Serve

Start local dev server.

$ npm start

Open in the browser:

Request

While the server is running, you can run these in another terminal tab.

$ curl http://localhost:3000/

$ curl http://localhost:3000/foo

$ curl http://localhost:3000/foo -X POST

$ # Form data.
$ curl http://localhost:3000/foo -X POST -d 'a=b'
$ # JSON data.
$ curl http://localhost:3000/foo -X POST -d '{"a": "b"}' -H "Content-Type: application/json"

$ curl http://localhost:3000/foo -X DELETE

$ curl http://localhost:3000/foo/123

$ curl http://localhost:3000/bar

$ # Verbose flag shows the error code.
$ curl -v http://localhost:3000/baz
$ curl -v http://localhost:3000/admin

Developer notes

Attributes of the request object

req.body
req.url
req.headers
req.query
req.params

Body parse

You do not need use use bodyparser package anymore to handle JSON body - see resources.

The .urlencoded middleware is needed to parse the form data. You pass explicitly pass it extended option (default is true), to avoid a deprecation warning. See express #3650.

The .json middleware parse JSON-formatted text for bodies with a Content-Type of application/json.

Resources

Related projects

  • MichaelCurrin - express-quickstart
  • MichaelCurrin - node-project-template

License

Released under MIT by @MichaelCurrin.

About

A base REST API project using Express and Node

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published