What is Nostr?
Ako Suminoe :njp: /
npub1tuq…axml
2023-07-10 18:07:19
in reply to nevent1q…68g5

Ako Suminoe :njp: on Nostr: The advantage of REST API there is that everyone uses the SAME request, so they get ...

The advantage of REST API there is that everyone uses the SAME request, so they get cached. If you add query parameters to determine what fields get returned, those become separate requests so they can't be cached together.

/api/my_object and /api/my_object?fields=a,b are two different requests, so the only technical advantage of REST API is gone. All consumers of the API need to be calling /api/my_object for caching to work between those two consumers. The same is true for things like including children and filters.

But including children is by far the best advantage of GraphQL. With a REST API, you would need to custom code a /api/my_object?include=my_child parameter for it to work. It can be done, but it all has to be custom and I hardly ever see it done in practice. GraphQL makes it trivial to not only include children but filter and select fields for them, too.

For a REAL WORLD example, I regularly have to call REST and GQL APIs at work. With REST APIs, I regularly end up making THOUSANDS of individual requests to get all the information that I need, while I can pack everything from GQL APIs into a SINGLE request (plus pagination). The GQL takes a lot less time and is far simpler.
Author Public Key
npub1tuqhwmqxj9g4aqjcw8gn42hugmvqwgquksejcrt3ztpnsmlm9cjq55axml