https://github.com/michaelcurrin/express-rest-quickstart
A base REST API project using Express and Node
https://github.com/michaelcurrin/express-rest-quickstart
base express nodejs rest-api
Last synced: 2 months ago
JSON representation
A base REST API project using Express and Node
- Host: GitHub
- URL: https://github.com/michaelcurrin/express-rest-quickstart
- Owner: MichaelCurrin
- License: mit
- Created: 2020-05-09T16:17:13.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-11-03T20:41:24.000Z (over 1 year ago)
- Last Synced: 2025-07-23T08:48:18.700Z (11 months ago)
- Topics: base, express, nodejs, rest-api
- Language: JavaScript
- Homepage:
- Size: 78.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Express JS REST Quickstart
> A base REST API project using Express and Node
[](https://github.com/MichaelCurrin/express-rest-quickstart/releases/)
[](#license)
[](https://www.npmjs.com/package/express)
## Requirements
- [Node.js](https://nodejs.org)
## Installation
### Install system dependencies
Install Node.js using this [gist](https://gist.github.com/MichaelCurrin/aa1fc56419a355972b96bce23f3bccba).
### Clone project
Clone repo.
```sh
$ git clone git@github.com:MichaelCurrin/express-rest-quickstart.git
$ cd express-js-create-app-quickstart
```
### Install project dependencies
```sh
npm install
```
## Usage
### Serve
Start local dev server.
```sh
$ npm start
```
Open in the browser:
- http://localhost:3000/
### Request
While the server is running, you can run these in another terminal tab.
```sh
$ 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
```javascript
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](https://github.com/expressjs/express/issues/3650).
The `.json` middleware parse JSON-formatted text for bodies with a Content-Type of `application/json`.
## Resources
- [expressjs.com](https://expressjs.com/) homepage.
- [express](https://www.npmjs.com/package/express) package on NPM.
- Express docs
- [Quickstart](https://expressjs.com/en/starter/hello-world.html)
- [Routing](https://expressjs.com/en/starter/basic-routing.html)
- [Route paths](http://expressjs.com/en/guide/routing.html#route-paths)
- [express Methods](http://expressjs.com/en/api.html#express.json)
- Posts
- [You may not need bodyparser](https://medium.com/@mmajdanski/express-body-parser-and-why-may-not-need-it-335803cd048c)
- [Get HTTP POST Body in Express.js](https://stackabuse.com/get-http-post-body-in-express-js/)
- [How to setup Express JS server](https://dev.to/kyrelldixon/how-to-setup-an-express-js-server-in-node-js-56hp) - includes how to test in multiple ways
## Related projects
- [](https://github.com/MichaelCurrin/express-quickstart)
- [](https://github.com/MichaelCurrin/node-project-template)
## License
Released under [MIT](/LICENSE) by [@MichaelCurrin](https://github.com/MichaelCurrin).