Skip to content

liammclennan/resourceserver

Repository files navigation

Resourceserver

TODO:

  1. Add validation

  2. Add pre/post hooks

Implements an in-memory (or persistent via redis) resource oriented HTTP server, provding 5 basic operations (shown in curl_tests.sh). Edit redis connection config in config.coffee.

POST /:collection

Create a new resource.

curl -vX POST http://localhost:3002/people \
  -H 'content-type: application/json' -d '{"name": "Liam", "age": 29}'
{
  "name": "Liam",
  "age": 29,
  "id": 2
}
curl -vX POST http://localhost:3002/people \
  -H 'content-type: application/json' -d '{"name": "Noah", "age": 1}'
{
  "name": "Noah",
  "age": 1,
  "id": 2
}

GET /:collection/:id

Retrieve the :collection resource with id :id.

curl -v http://localhost:3002/people/1
{
  "name": "Liam",
  "age": 29,
  "id": 1
}

GET /:collection

Retrieve an array of all :collection resources.

curl -v http://localhost:3002/people
[
  {
    "name": "Liam",
    "age": 29,
    "id": 1
  },
  {
    "name": "Noah",
    "age": 1,
    "id": 2
  }
]

PUT /:collection/:id

Override the :collection resource with id :id.

curl -vX PUT http://localhost:3002/people/1 \
  -H 'content-type: application/json' -d '{"name": "LiamO", "age": 30}'
{
  "name": "LiamO",
  "age": 30,
  "id": "1"
}

DELETE /:collection/:id

Delete the :collection resource with id :id.

curl -vX DELETE http://localhost:3002/people/1

It uses the CORS headers to allow cross-origin requests.

Usage

  1. Clone the repository

  2. Install node.js

  3. Install the dependencies with npm install

  4. Start the server with npm start

  5. [Optional] Run tests with cd test && ./curl_tests.sh

About

Implements an in-memory resource oriented HTTP server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •