resourceserver
resourceserver copied to clipboard
Implements an in-memory resource oriented HTTP server
Resourceserver
TODO:
-
Add validation
-
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
-
Clone the repository
-
Install node.js
-
Install the dependencies with
npm install
-
Start the server with
npm start
-
[Optional] Run tests with
cd test && ./curl_tests.sh