swapi icon indicating copy to clipboard operation
swapi copied to clipboard

Include id for a given resource in list view

Open mikkelrd opened this issue 8 years ago • 5 comments

For example, when querying /people, the individual records don't have an id property, but this would be terribly useful and be in line with common RESTful api practice. It would be more useful for using SWAPI as a fake backend to test some front end functionality than simply relying on the url field.

mikkelrd avatar Apr 18 '17 21:04 mikkelrd

Why isn't the url sufficient enough? You would have to construct the URL anyway with the ID param? It's actually more HATEOAS (http://phalt.co/what-is-hateoas/) to use full URLs and not IDs :)

phalt avatar Apr 19 '17 10:04 phalt

For a basic API (which SWAPI is), providing the URL is sufficient.

However, in a more powerful and complicated structure, having access to the id is crucial. For example, you could expand the functionality of your planets service. Maybe it could take an array of character IDs and return a list of all the planets those characters have every visited.

The ability to compose IDs with services is crucial in modern API architecture. A model shouldn't have to provide a URL for every place that it can be used.

This clearly isn't crucial for SWAPI. But I often use SWAPI when teaching developers to consume APIs. Having SWAPI act a bit more like the average API would definitely be helpful.

jacob-israel-turner avatar Apr 20 '17 16:04 jacob-israel-turner

I'm currently implementing an APL-Wrapper for SWAPI and was surprised by the same. I see the point about HATEOAS, but I'm also with @jacob-israel-turner on that ;) Guess I will create the IDs myself from the URL then and provide a health-warning...

mbaas2 avatar Oct 08 '19 10:10 mbaas2

hi @mbaas2 , have you created the IDs from the URL parameter? I will be so thankfull if you can give me a snippet from your code.

Thanks!

luismigil avatar Mar 27 '21 01:03 luismigil

@luismigil Sure, no problem: it's here.

mbaas2 avatar Mar 27 '21 08:03 mbaas2