<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE> [99s-extend] I need your feedback about this cowboy_rest handler.
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:extend%40lists.ninenines.eu?Subject=Re%3A%20%5B99s-extend%5D%20I%20need%20your%20feedback%20about%20this%20cowboy_rest%0A%09handler.&In-Reply-To=%3CC563DB6C-5C79-4E13-929B-25C64B13DCD0%40wirtel.be%3E">
<META NAME="robots" CONTENT="index,nofollow">
<style type="text/css">
pre {
white-space: pre-wrap; /* css-2.1, curent FF, Opera, Safari */
}
</style>
<META http-equiv="Content-Type" content="text/html; charset=us-ascii">
<LINK REL="Previous" HREF="000449.html">
<LINK REL="Next" HREF="000451.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[99s-extend] I need your feedback about this cowboy_rest handler.</H1>
<B>Stéphane Wirtel</B>
<A HREF="mailto:extend%40lists.ninenines.eu?Subject=Re%3A%20%5B99s-extend%5D%20I%20need%20your%20feedback%20about%20this%20cowboy_rest%0A%09handler.&In-Reply-To=%3CC563DB6C-5C79-4E13-929B-25C64B13DCD0%40wirtel.be%3E"
TITLE="[99s-extend] I need your feedback about this cowboy_rest handler.">stephane at wirtel.be
</A><BR>
<I>Wed Aug 27 12:35:33 CEST 2014</I>
<P><UL>
<LI>Previous message: <A HREF="000449.html">[99s-extend] I need your feedback about this cowboy_rest handler.
</A></li>
<LI>Next message: <A HREF="000451.html">[99s-extend] I need your feedback about this cowboy_rest handler.
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#450">[ date ]</a>
<a href="thread.html#450">[ thread ]</a>
<a href="subject.html#450">[ subject ]</a>
<a href="author.html#450">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>On 27 Aug 2014, at 12:03, Loïc Hoguin wrote:
><i> Hey,
</I>><i>
</I>><i> On 08/27/2014 12:29 PM, Stéphane Wirtel wrote:
</I>>><i> Hi all,
</I>>><i>
</I>>><i> This night, I wrote an example because I wanted to show you my work.
</I>>><i>
</I>>><i> I have one handler for the concept of collections (in this case,
</I>>><i> tasks).
</I>>><i>
</I>>><i> In this handler, I want these following methods:
</I>>><i>
</I>>><i> POST /:collection
</I>>><i> GET /:collection
</I>>><i> DELETE /:collection
</I>>><i> PUT /:collection
</I>>><i> HEAD /:collection
</I>>><i>
</I>>><i> :collection is a string, example: /tasks1
</I>>><i>
</I>>><i> HEAD /:collection (/tasks1)
</I>>><i> StatusCode:
</I>>><i> * 200 ok
</I>>><i> * 404 not found
</I>>><i>
</I>>><i> GET /:collection (/tasks1)
</I>>><i> Gets information about the collection
</I>>><i> StatusCode:
</I>>><i> * 200 ok
</I>>><i> * 404 not found
</I>>><i>
</I>>><i> PUT /:collection (/tasks1)
</I>>><i> Create a new collection of tasks
</I>>><i> Status_Code:
</I>>><i> * 201 created
</I>>><i> Response: an object, in msgpack or json and I need to had a
</I>>><i> location header
</I>>><i> * 412 precondition failed, the collection name already exists
</I>>><i> Response: an object, in msgpack or json with the error (already
</I>>><i> exists)
</I>>><i>
</I>>><i> POST /:collection (/tasks1)
</I>>><i> Add a new item in the collection, a new task
</I>>><i> StatusCode:
</I>>><i> * 201 created
</I>>><i> * 202 accepted
</I>>><i> * 404 not found (error in the collection name)
</I>>><i> Response: need to add a location header and return an object in
</I>>><i> msgpack
</I>>><i> or json.
</I>>><i>
</I>>><i> DELETE /:collection (/tasks1)
</I>>><i> Delete all the tasks
</I>>><i> Status_Code:
</I>>><i> * 200 ok.
</I>>><i> * 404 not found
</I>>><i> In the case of 200, we need to return an object in msgpack or json.
</I>>><i>
</I>>><i>
</I>>><i> I provided a code and If you can help me, because I think cowboy_rest
</I>>><i> is
</I>>><i> a good solution, but I also think I will have some problems with my
</I>>><i> service.
</I>>><i>
</I>>><i> Examples:
</I>>><i> * delete_completed, I need to write the serialisation in the
</I>>><i> delete_completed function and not with the help of the defined
</I>>><i> callbacks
</I>>><i> of content_types_provided.
</I>><i>
</I>><i> What's the problem? The callbacks you set in content_types_provided
</I>><i> are there to provide the *resource*. If you set a body in response to
</I>><i> the DELETE method you are not sending the resource but information
</I>><i> about the result of the operation.
</I>Ok, in this case, I understand. thanks
><i>
</I>>><i> * for PUT, I need to return a location header, should I add it in the
</I>>><i> is_conflict
</I>>><i> function?
</I>><i>
</I>><i> I would say in the callback you set in content_types_accepted. But...
</I>Works fine in the is_conflict function.
><i>
</I>>><i> * for PUT, how I have a 201? I have read the rest_flowchart and I
</I>>><i> need
</I>>><i> to specify the location header ok, but where? in the is_conflict
</I>>><i> function?
</I>><i>
</I>><i> Why do you need a 201? If you PUT a collection to /:collection then
</I>><i> this is already the location of the collection. I am not sure what you
</I>><i> are trying to do there exactly?
</I>In this case, the PUT method is used for the creation of the resource
and not for the update. This is the reason of the 201 status code.
In the rest_flowchart graph for the PUT/POST methods, what is the node
"new resource" ? Is it just the {true, Req, State} from the callback
defined in the content_types_accepted?
PS: I retested and now, I have my 201 with PUT, just resource_exists has
to return false and not true ;-)
Thanks
--
Stéphane Wirtel - <A HREF="http://wirtel.be">http://wirtel.be</A> - @matrixise
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI>Previous message: <A HREF="000449.html">[99s-extend] I need your feedback about this cowboy_rest handler.
</A></li>
<LI>Next message: <A HREF="000451.html">[99s-extend] I need your feedback about this cowboy_rest handler.
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#450">[ date ]</a>
<a href="thread.html#450">[ thread ]</a>
<a href="subject.html#450">[ subject ]</a>
<a href="author.html#450">[ author ]</a>
</LI>
</UL>
<hr>
<a href="https://lists.ninenines.eu/listinfo/extend">More information about the Extend
mailing list</a><br>
</body></html>