RejectedSoftware Forums

Sign up

vibe.http.rest Need support for JsonRest

Hi,
first of all : GREAT WORK!

What I need is JSONRest support following RFC 2616.
( http://www.ietf.org/rfc/rfc2616.txt )

I would like to use vibe.d as REST Server back-end in conjunction with
dojo/dijit (front-end) to implement RIAs.

This means that certain things should work as follows.

----Method mapping : (pretty much the same I've asked for on D.announce)
get(id) :

  • This will trigger a GET request to {target}{id}.

query(query, options)

  • This will trigger a GET request to {target}{query}. If query is an
    object, it will be serialized using dojo.objectToQuery. If query is a
    string, it is appended to the URL as-is. If options includes a sort
    property, it will be serialized as a query parameter as well; see
    Sorting for more information.

remove(id) :

  • This will trigger a DELETE request to {target}{id}.

put(object, options) :

  • If object includes an identity property, or options includes an id,
    this will trigger a PUT request to {target}{id} with the request body
    being the provided object serialized as JSON. If no identity is
    provided, then a POST request is made to the store’s target URL (no id
    appended) with the object as the body. If the options.incremental
    property is true, then a POST request is made to {target}{id} with the
    object as the body. You may also include an options.overwrite property.
    If overwrite is set to true, then an If-Match: header is included. If
    overwrite is set to false, then an If-None-Match:
    header is included

add(object, options) :

  • This behaves exactly like put(object, options), except that
    options.overwrite is set to false, indicating that a new object must be
    created.

------Paging : (Requires Range header support, and is required to handle
huge collections/database-tables)

JsonRest store uses HTTP’s Range header to perform paging. When a
request is made for a range of items, JsonRest will include a Range
header with an items range unit specifying the range:

 Range: items=0-24

On your server, you should look at the Range header in the request to
know which items to return. The server should respond with a
Content-Range header to indicate how many items are being returned and
how many total items exist:

 Content-Range: items 0-24/66

-------Sorting :
When a query request is made that includes a sort option in the options
object, an additional sort field is added to the query string. If the
store’s sortParam property is set, it will use that value as the key for
the field in the query string.

For example, given the following store and request:

var store = new JsonRestStore({
target: "/FooObject/",
sortParam: "sortBy"
});

store.query({ foo: "value1" }, {
sort: [

 { attribute: "foo" },
 { attribute: "bar", descending: true }

]
});

The resulting request to the server would be:

 /FooObject/?foo=value1&sortBy=+foo,-bar

If sortParam is not set, the sort value is appended without a key-value
pair, surrounded by “sort()”:

 /FooObject/?foo=value1&sort(+foo,-bar)


.... Hope this makes sense to you.
Bjoern

Re: vibe.http.rest Need support for JsonRest

Am 19.05.2012 17:38, schrieb Pragmatix:

Hi,
first of all : GREAT WORK!

What I need is JSONRest support following RFC 2616.
( http://www.ietf.org/rfc/rfc2616.txt )

I would like to use vibe.d as REST Server back-end in conjunction with
dojo/dijit (front-end) to implement RIAs.

This means that certain things should work as follows.

I have some additions planned for the current generator, which is still
very simple, but I'm not yet 100% sure about them.

http://vibed.org/api/vibe.http.rest#registerRestInterface

Unfortunately, right now, my schedule is extremely tight. I will look
closer into your list of features once there some more time again -
range and query definitely sound like good additions.

Re: vibe.http.rest Need support for JsonRest

Am 19.05.2012 22:18, schrieb Sönke Ludwig:

Am 19.05.2012 17:38, schrieb Pragmatix:

Hi,
first of all : GREAT WORK!

What I need is JSONRest support following RFC 2616.
( http://www.ietf.org/rfc/rfc2616.txt )

I would like to use vibe.d as REST Server back-end in conjunction with
dojo/dijit (front-end) to implement RIAs.

This means that certain things should work as follows.

I have some additions planned for the current generator, which is still
very simple, but I'm not yet 100% sure about them.

http://vibed.org/api/vibe.http.rest#registerRestInterface

Unfortunately, right now, my schedule is extremely tight. I will look
closer into your list of features once there some more time again -
range and query definitely sound like good additions.

Danke Sönke , fair enough.
means for me that I can start working on the QR-code encoder/decoder.
btw. in case that you can spend a few minutes.. have a look at the zeal
REST implementation.

Re: vibe.http.rest Need support for JsonRest

Am 19.05.2012 22:26, schrieb Pragmatix:

Am 19.05.2012 22:18, schrieb Sönke Ludwig:

Am 19.05.2012 17:38, schrieb Pragmatix:

Hi,
first of all : GREAT WORK!

What I need is JSONRest support following RFC 2616.
( http://www.ietf.org/rfc/rfc2616.txt )

I would like to use vibe.d as REST Server back-end in conjunction with
dojo/dijit (front-end) to implement RIAs.

This means that certain things should work as follows.

I have some additions planned for the current generator, which is still
very simple, but I'm not yet 100% sure about them.

http://vibed.org/api/vibe.http.rest#registerRestInterface

Unfortunately, right now, my schedule is extremely tight. I will look
closer into your list of features once there some more time again -
range and query definitely sound like good additions.

Danke Sönke , fair enough.
means for me that I can start working on the QR-code encoder/decoder.
btw. in case that you can spend a few minutes.. have a look at the zeal
REST implementation.

I had some time to make some first extensions. You can now have a method
'index' that acts as a "GET /" on the base folder specified and If the
first parameter is named 'id', it is translated as a directory name
(e.g. getName(id) -> GET /:id/name).

The "Range: ..." stuff needs some more thought on how to fit it nicely
into the API. An alternative would be to make an explicit JsonRestStore
implementation, because the scope of the registerRestInterface() is a
bit more general, but that would be something for someone else because I
would neither be able to properly test it nor would I use it.

I've looked at zeal.d before and I like it and would also consider it
for new apps. However, the goal of the http.rest stuff is more to have a
seemless D-to-D RPC facility.

Btw. one other aspect to think about would be how to best integrate
authroization checks.

Re: vibe.http.rest Need support for JsonRest

Am 23.05.2012 15:37, schrieb Sönke Ludwig:

I had some time to make some first extensions. You can now have a method
'index' that acts as a "GET /" on the base folder specified and If the
first parameter is named 'id', it is translated as a directory name
(e.g. getName(id) -> GET /:id/name).

The "Range: ..." stuff needs some more thought on how to fit it nicely
into the API. An alternative would be to make an explicit JsonRestStore
implementation, because the scope of the registerRestInterface() is a
bit more general, but that would be something for someone else because I
would neither be able to properly test it nor would I use it.

Thanks for REST/DELETE support. I think this feature is a win .. Seems
that there is just the Range stuff left to make the REST service
complete and versatile / usable.

Bjoern