Reputation: 641
I'm working on a REST api, and thinking about cutting down on development time by using the Loopback framework.
I like a lot of things about the framework (and it seems to fit my needs), but I completely dislike this:
http://localhost:3000/api/users?filter[where][username]=john&filter[where][email][email protected]
http://localhost:3000/api/users?filter={"where":{"username":"john","email":"[email protected]"}}
If you have a model that you expose as a REST api, that's how your urls look like. For me both options look strange and kind of ugly. And things seem even weirder when you get to examples like this /cars?filter[where][miles][gt]=5000
.
So, can I somehow change the form of the url for all exposed models? (to something more traditional). I would really like to have normal query strings like:
http://localhost:3000/api/users?username=john&[email protected]
Is there a reason they look like that and that I should appreciate over looks? Any REST apis with this syntax around?
Thanks
Upvotes: 5
Views: 3041
Reputation: 2610
Loopback provides a REST interface for your models, with the ability to carry out quite complex queries against the data without any additional coding required. I think they have modelled the syntax on the OData standard. So that is why the querystring is more complex than you might expect.
In Loopback you can create your own, custom end points by using Remote Methods, so you could create and expose an endpoint like getuser
which took in the parameters you specified, resulting in a much simpler API.
Upvotes: 1