-
Notifications
You must be signed in to change notification settings - Fork 834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Requesting filters or conditions #21
Comments
I'd imagine this would happen the normal way, via the URI template. You'd include parameters to make this happen. |
Since I'm just arriving, I can't figure out from the Reading page how to use templates for anything other than relations, but I'm excited to find out what that looks like when an example gets added. :) |
(that should get added, yes) |
Yup. Also easily accomplished through profiles. |
Just to make things super explicit — there will be an example of doing this in the Extending section? Or no? |
Sure, if it's useful. Seems good. |
Seems related to #45 |
Any chance we can get one or two examples of how to implement filters/conditions via Profiles and URL Templates? I've read both RFCs and I'm afraid I don't feel I'm any closer to figuring out how they apply to querying resources. Would it be possible to re-open this ticket until such examples are published with the JSON API specification? Imagine I have a {
id: 1234,
title: "Profiles, WTF?",
keywords: [ "rfc", "ietf", "http" ],
authors: [
{ name: "bob", email: "bob@bob.bob" }
],
publisher: {
name: "alice inc",
date: "2013-11-07",
}
} What could I put in my What would HTTP requests look like to perform these example searches? What if I have a bunch of different resource types with similar search characteristics (e.g. JSON API already uses Thanks in advance for any assistance you can provide. :) |
I don't have time to get into it right this moment, but this will end up in the FAQ. The super short answer is a link in the meta that looks something like http://amundsen.com/media-types/collection/examples/#ex-queries |
There's also http://jsonapi.org/extending/ which describes an example of pagination, but you could see how it would work with any kind of query. |
@steveklabnik Thanks! Some questions: Param names that are composites of various behavior like that which is provided via has_scope (used by Inherited Resources) might be difficult to describe, e.g. scope chaining with URL path The abilities provided for filtering by Thanks again! |
To summarise my understanding of this:
The thing I love about JSON API is that it takes what we already know from HTTP and REST and fills in many of the questions surrounding URL schemes, MIME types and request/response bodies. Awesome. In that spirit, I personally would find it awesome if one day JSON API could specify how searches should be requested: what the URL query parameters look like and how we filter based on any data structure our JSON API would otherwise be able to return. I realise that it's incredibly difficult to come up with a specification that solves every problem, so it's totally fair if this is a long-term nice-to-have feature of an otherwise already productive specification. @garysweaver your order chain example |
@jokeyrhyme Thanks! Irie supports comma-delimited order value also, e.g. order=-color,-price,name. I'm also a fan of its filtering syntax but I'm partial. :) |
In case anyone was interested, I settled on MongoDB's query syntax:
Our implementation:
Simple queries look simple, but cover all the bases. My URLs look like this:
We can mix it with the JSON API
Note: this is just proposed syntax specification. This helps document to API consumers what they can put in their request URLs, but the actual server-side implementation is separate. I looked at JSONiq, CouchDB and a few other JSON-specific query specifications, but MongoDB's seemed the shortest and most comprehensive. I don't feel any solution based only on RDBMS with columns and no true appreciation of JSON structures should be considered for inclusion in the JSON API specification. |
@jokeyrhyme I'm not averse to more syntax if it is necessary, but I think the URL query syntax used in Irie, such as Brackets such as seen in In both ...unfortunately this discussion will go into a rathole if we discuss differences in opinion about what the URL should look like. IMO, the real question is: "Is there anything specifically about json-api as it currently stands that could be changed so that we could move forward in an effort to define standards for querying data through JSON?" I think the answer is "maybe". Basically, I think the structure of
|
This is basically true.
In theory, they are! Except that The reason to mint a new type is so that we can share the 80% that's the same, and only specialize on the 20% that is different. If it were entirely in a profile, you'd still need to fully re-implement for each one, which doesn't gain you anything. |
@steveklabnik The thing I worry about though is that the extras are as much part of the overall definition as the 80% that is the same. API composition can be as piecemeal as you wish but integration is most likely a singular activity, i.e. if you have fuzzy things like profile and meta, that isn't going to be automatically capable of integration by a client until we have a Skynet/Terminator-level of AI on the client-side, so a human is going to have to read all those profile URL docs and then integrate, which is a PITA that the 80% doesn't solve. In short- the 80% done in 100% of cases provides little, but 100% done in 80% of the cases buys a lot more. Without query param standardization, you aren't 100% done in 80% of the cases. |
@garysweaver I don't want to force MongoDB syntax on everyone. I just wish there was a better alternative. Irie is a good start. Here are my problems with it:
I feel having clearly separate namespaces makes parsing easier, syntax less ambiguous and makes knowledge of the JSON API specification more portable. It also frees developers to use whatever JSON structure they feel depicts their domain objects without fear of collisions with reserved keywords. I know @steveklabnik an advantage of making some searching syntax part of the JSON API specification: if I already know JSON API, then I can immediately start using an API without needing to first read about the specific quirks the owner implemented regarding searches. |
@jokeyrhyme Typically when you expose an API for an application, you are doing so for the specific behavior required by the application. Irie does that. Like typical controller development, you have to declare what is possible, specifically. The syntax that you are proposing to be standard used by Mongo would appear to be not-so-specific, which would appear to make an application developer more likely to expose data that their application does not need, which is usually not a good idea. Is that the case, or am I missing something? Also, Irie does not inhibit the user from adding a prefix to any parameter name. The examples I provided were to show the simplest case. I'm not against a prefix, if it is required. I just as of yet have not seen a reason for one. For parameter values in the syntax you are proposing, it appears to require a lot of parameter value manipulation just to get the value out for something that is specific and declarative, and if it is unspecific, you are probably exposing more than you need. I'm not against such an elaborate syntax if it were the most common case and it were to become standard, but allowing that level of access to the data to a public user without it being specifically declared to be so is not common in my experience. |
True, but conventions are so powerful, and JSON API already specifies conventions for compound documents (
I'm not proposing the MongoDB syntax, rather I am using it as an example of a good one. Above all else, I think it exemplifies a JSON-first query language, unlike all the SQL-first stuff
Only if they implement it that way. I'm primarily interested in implementing filters for GET and HEAD, not for DELETE, PATCH, POST or PATCH (although others are free to if they need it). What exactly is the harm in being able to filter on any field in the JSON that you can already retrieve with GET?
|
I'm not saying Mongo is bad; I'm saying that if the standard for any application that wanted to provide a standard JSON API to query data is to provide a way to query exactly like Mongo, you'd have to ensure that query could be locked down to only provide the specific access to the data that the server allowed, and it's not clear to me what benefit there would be to using the Mongo syntax if only specific parts are allowed, because it is a little verbose and requires parsing of the request param value to get values that form part of the query vs. the entire param value being the dynamic part. In Irie's case, order is the only one like that that requires parsing.
Nothing, as long as there is no way to construct the query to provide access that was not intended. For example, if the data is extremely large, you may want to cache certain types of queries and only allow those queries, while still conforming to the json-api spec for those types of queries. I just want to ensure that if you are suggesting that anything can be queried that is part of the resource or the resource "tree" with a custom query, then that may be going further than many application developers might want to go. |
Okay, last one that immediately jumps out at me: in order to filter or limit the data that will be returned by some criteria, Rails has scopes and SQL has WHERE. Will there be a (presumably optional) section of the specification that provides a convention for clients that want, say, only the open issues on a specific repo, and none of the closed ones? Or only the draft posts, and none of the posted ones?
The text was updated successfully, but these errors were encountered: