REST Interface should always return valid JSON
While most API calls result in valid JSON, some like document creation do not. Document creation results in simply the recordID being set (e.g. #10:0). This is makes building client libraries more complex as the results can't be relied upon to be valid JSON
I agree that this is a major shortcoming in the rest(ish) API. Another alternative is that the create document request could return a location header pointing to the created document eg: LOCATION: /document/{db}/{rid}
Hi, Maybe it could return both the Location Header and the serialized document in json format. However I think that the http protocol indicates that there is the Location header and HTTP code 301.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30 Il giorno 16/apr/2013 10:30, "Mat Taylor" [email protected] ha scritto:
I agree that this is a major shortcoming in the rest(ish) API. Another alternative is that the create document request could return a location header pointing to the created document eg: LOCATION: /document/{db}/{rid}
— Reply to this email directly or view it on GitHubhttps://github.com/nuvolabase/orientdb/issues/1438#issuecomment-16432481 .
I definitely agree with the Location header idea. I could go either way on the body containing the finalized object.
Hi like the LOCATION solution, but how can we avoid to break the compatibility with existent driver based on HTTP? We could support Location but continue to return such RID?
The best way to use the location header is to return a 201 rather than a 200. as 201 + location is telling the client where the created document resides. I would also like to see the fully created object also returned in the response body as this would minimise the need for a subsequent request.
One way to preserve back compatability is to package this new behavior as a seperate API call using the 'document by class' end point. i.e.
POST /documentbyclass/<database>/<class-name>/
An advantage of this is that you could create documents without having to specify the @class parameter as this would be infered from the URI
@mattaylor is right about the 201, that's a good call.
I disagree with the documentbyclass solution in that this behavior should exist for non-schema'd documents as well. In this case, I would chalk this up to a bug and just fix it outright. The REST interface is hardly a stable solution at the moment (some endpoints return improperly formatted JSON with missing commas etc) so I don't think too much would be lost.
On the question of breaking existing HTTP client libraries, a bump in the major version number according to the semantic versioning scheme allows you to break backwards compatibility. That's exactly what it's for, and it's worth doing this now before OrientDB takes over a large share of the NoSQL storage world, which it looks like it's about to, so pack it in with 2.0.0 ;-)
Hey guys, this thread is becoming hot ;-) To be honest I think I was drunk when I wrote the /document HTTP API. I think that the return should always be JSON, so I'd like to fix it asap. We manage the JS driver directly but we've to contact all the [email protected] about this change. I think 1.4 is a good chance because we already changed the /connect to avoid returning the entire db schema every time, so driver developers to be compatible with 1.4 and further already had to change own driver. WDYT?
Hi, if you wish to do a refactoring of the REST API and JSON, I suggest to use the JSON schema too. JSON Schema specifies the structure of a JSON document and can be used to validate the content of JSON sent to, or received from, RESTful Web Service. The reference site is http://json-schema.org where there are specifications, docs and examples.
2013/4/28 Luca Garulli [email protected]
Hey guys, this thread is becoming hot ;-) To be honest I think I was drunk when I wrote the /document HTTP API. I think that the return should always be JSON, so I'd like to fix it asap. We manage the JS driver directly but we've to contact all the [email protected] about this change. I think 1.4 is a good chance because we already changed the /connect to avoid returning the entire db schema every time, so driver developers to be compatible with 1.4 and further already had to change own driver. WDYT?
— Reply to this email directly or view it on GitHubhttps://github.com/nuvolabase/orientdb/issues/1438#issuecomment-17143013 .
Sent from my Commodore 64
+1 for JSON schema. The REST API shoul dalso provide a way to override the '#' (e.g. replace with a '$') as used in rid's as these are very un URL friendly, not sure how these would play with JSON REF though.
A final ask is that JSON5 could be supported allowing unquoted keys any other niceties.
This all sound more like a 2.0 type exercise to me though
Matt, AFAIK all the HTTP API get the RID without # in request.
Even without the hash you get:
9:0
This is not valid JSON. A quick fix would be:
"9:0"
Which is more acceptable but still not very informative.
{
"rid": "9:0"
}
Is definitely a lot better, though a full object would be even nicer.
Luca,
I realize that, however in the context of JSON schema, (hyper schema specifically) ideally you would really want to be able to describe related URL's in terms of the properties of the objects they reference. For example ...
{ title:'user', type: 'object', properties: { id: { type:'string' }, db: { type:'string' }, name: { type:'string' } } links: [ { rel:"self", url:"/document/{db}/{id} } ] } Thanks, Mat
On Apr 29, 2013, at 6:35 AM, Luca Garulli [email protected] wrote:
Matt, AFAIK all the HTTP API get the RID without # in request.
— Reply to this email directly or view it on GitHub.
No JSON schema for now, sorry. Could you open a new issue for that?