Skip to content

Commit

Permalink
Return 201 status from POST collection endpoint
Browse files Browse the repository at this point in the history
-Resolve task in Issue #48
  - 201 is the standard HTTP response code when a resource is created,
    which is done in a POST collection endpoint.
- Update README to include info about successful response codes (just a
  band-aid fix until the apiDoc is ready)
  • Loading branch information
kahmali committed Jul 2, 2015
1 parent ad380e8 commit d4f95f8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,8 @@ object containing the following properties:
### Request and Response Structure
All responses generated by Restivus follow the [JSend] format, with one minor tweak: failures have
an identical structure to errors. Sample requests and responses for each endpoint are included
below:
an identical structure to errors. Successful responses will have a status code of `200`, unless
otherwise indicated. Sample requests and responses for each endpoint are included below:
#### `post`
Request:
Expand All @@ -485,6 +485,8 @@ curl -X POST http://localhost:3000/api/posts/ -d "title=Witty Title" -d "author=
```
Response:
Status Code: `201`
```json
{
"status": "success",
Expand Down Expand Up @@ -623,6 +625,8 @@ name in the [Accounts.createUser()](http://docs.meteor.com/#/full/accounts_creat
check that out for more information on how those fields are handled._
Response:
Status Code: `201`
```json
{
"status": "success",
Expand Down
8 changes: 5 additions & 3 deletions lib/restivus.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,11 @@ class @Restivus
entityId = collection.insert @bodyParams
entity = collection.findOne entityId
if entity
{status: "success", data: entity}
statusCode: 201
body: {status: "success", data: entity}
else
statusCode: 400
{status: "fail", message: "No item added"}
body: {status: "fail", message: "No item added"}
getAll: (collection) ->
get:
action: ->
Expand Down Expand Up @@ -230,7 +231,8 @@ class @Restivus
entityId = Accounts.createUser @bodyParams
entity = collection.findOne entityId, fields: profile: 1
if entity
{status: "success", data: entity}
statusCode: 201
body: {status: "success", data: entity}
else
statusCode: 400
{status: "fail", message: "No user added"}
Expand Down

0 comments on commit d4f95f8

Please sign in to comment.