-
Notifications
You must be signed in to change notification settings - Fork 13
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
Improve API Methods #129
Comments
We have two methods that I think are too similar to keep - but I want to see what anyone here might think: GetEntries = GET /api/streams/{stream}/entries GetEntries is GET only and supports a LIMITED fixed filtering style using the query string. Both methods currently force pagination (even if you ask for 999,999 per page). https://github.com/laravel-streams/streams-api/blob/1.0/tests/Http/Controller/Entries/GetEntriesTest.php A repository endpoint also allows calling repository methods and passing query string payloads—a tentative method right now; also not sure if it's necessary. I don't like that repositories can return collections or single entries. So that would mean the API endpoint may do the same depending on the return of the repository method... |
Removed the repository method. |
Ugh, we need GET on querying because of cache control. |
I don't really like the idea of 3 different endpoints for pretty much the same data. Query strings have quite some limitations in terms of nested key-value stuff. By using a JSON request body like: {
where : [
[ 'a', '==', 'b' ],
[ 'b', '==', 'where it\'s always super & nice' ],
],
per_page: 10,
paginate: true,
} We can easily pass that to the Criteria instance in the backend. We can combine multiple criteria methods, including pagination and be awesome with 1 single endpoint. |
It seems as though GET and request bodies violate standards: https://stackoverflow.com/questions/978061/http-get-with-request-body |
I am thinking that we need a query method using post to query with request body. Won’t be technically idempotent, which is accurate.. and we can cache differently, internally. Agreed on the duplicate endpoints though. |
Ah, using “Expires header or a Cache-Control.” So question is, do we need a repository GET method. And the POST method will utilize request body and support criteria methods. Thinking about stuff like get home page, get navigation, stuff that’s potentially constantly used. |
It does not actually violate it i think. From the same stackoverflow answer:
Also interesting is:
So i still believe having a GET request body is worth considering. IMO POST should be used to create a resource, not to query/fetch resource.
|
The whole thing with JS flat-out not supporting it is a hard blocker. If it helps, we can look at it as creating a new query. And we still have caching opportunities. |
GET /streams/{stream}/entries/{method?} -> Repository::$method(...[$query]) |
Gonna tighten and write that - update tests. Pretty close to that now already. This is going to require tapping into repository reading via attributes at some point to document the non-universal endpoints. Repository returns, input/parameters, etc, all need generated from the attributes. |
Going to move this repository/criteria idea to a separate issue and label it for post-release. Current routes work well and are all tested. @RobinRadic would be an ideal time to give into the ApiClient Quick and dirty README and checkout tests while I work on docs: https://github.com/laravel-streams/streams-api |
GET /api/streams/{stream}/entries
POST /api/streams/{stream}/entries/{criteria-method}
GET /api/streams/{stream}/entries/{repository-method}
This will allow easier extension using logic that belongs in these patterns in the first place, removing the need for API specific controllers to be used just to access methodology in the design patterns mentioned above. Annotate and use. Use them all the same in your codebase.
Safelist and perhaps use annotations to denote which methods are API safe.
The text was updated successfully, but these errors were encountered: