[99s-extend] I need your feedback about this cowboy_rest handler.

Stéphane Wirtel stephane at wirtel.be
Wed Aug 27 11:29:46 CEST 2014


Hi all,

This night, I wrote an example because I wanted to show you my work.

I have one handler for the concept of collections (in this case, tasks).

In this handler, I want these following methods:

POST /:collection
GET /:collection
DELETE /:collection
PUT /:collection
HEAD /:collection

:collection is a string, example: /tasks1

HEAD /:collection (/tasks1)
StatusCode:
	* 200 ok
	* 404 not found

GET /:collection (/tasks1)
Gets information about the collection
StatusCode:
	* 200 ok
	* 404 not found

PUT /:collection (/tasks1)
Create a new collection of tasks
Status_Code:
	* 201 created
	Response: an object, in msgpack or json and I need to had a location 
header
	* 412 precondition failed, the collection name already exists
	Response: an object, in msgpack or json with the error (already exists)

POST /:collection (/tasks1)
Add a new item in the collection, a new task
StatusCode:
	* 201 created
	* 202 accepted
	* 404 not found (error in the collection name)
Response: need to add a location header and return an object in msgpack 
or json.

DELETE /:collection (/tasks1)
Delete all the tasks
Status_Code:
	* 200 ok.
	* 404 not found
In the case of 200, we need to return an object in msgpack or json.


I provided a code and If you can help me, because I think cowboy_rest is 
a good solution, but I also think I will have some problems with my 
service.

Examples:
* delete_completed, I need to write the serialisation in the 
delete_completed function and not with the help of the defined callbacks 
of content_types_provided.
* for PUT, I need to return a location header, should I add it in the 
is_conflict
function?
* for PUT, how I have a 201? I have read the rest_flowchart and I need 
to specify the location header ok, but where? in the is_conflict 
function?

So, do you have time to help me, because with this example, I can 
propose it to the cowboy repository.
https://github.com/matrixise/demo_rest/blob/master/src/collection_handler.erl

You can propose your PR, comments or remarks, but I would like to use 
cowboy_rest.

Regards,

Stephane

--
Stéphane Wirtel - http://wirtel.be - @matrixise


More information about the Extend mailing list