Juriy / swapi

SWAPI - Star Wars API service
https://swapi.dev
BSD 3-Clause "New" or "Revised" License
286 stars 91 forks source link

Sort resource and search results #3

Open donavon opened 4 years ago

donavon commented 4 years ago

I'd like to make a feature request. It would be nice if you could sort the results from a resource and a search. For example, search for https://swapi.dev/api/people/?search=a and you will get 58 results, but only the first 10 are returned. So any UI would likely display these items with a "next page" button. They appear to be sorted by ID, making the order of the pages meaningless, and even a bit confusing to the user.

I'd like to see something like ?sort=[name:asc, hair_color:desc] (ie. sort first by name in ascending order, then by hair color in descending order).

Or at a very minimum sort=asc, which would sort by the "main" field in ascending order. The "main" field would likely be name or title.

If this were JavaScript, I'd submit a PR myself.

Thought?

donavon commented 4 years ago

I did a little poking around and found this package which could help https://github.com/AltSchool/dynamic-rest

leonidpodriz commented 4 years ago

It looks like this? https://swapi-new.herokuapp.com/api/planets/?search=tatoo