Skip to content
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

wip: rest response sizes #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

matthewtrask
Copy link
Contributor

wip

@matthewtrask
Copy link
Contributor Author

@philsturgeon can you give me some feedback up to this point?

Copy link

@philsturgeon philsturgeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cracking start chap!

_posts/2019-03-09-rest-response-size.md Show resolved Hide resolved
"relationships": {
"user": {
"links": {
"self": "https://apisyouwonthate.com/api/users/11122/relationships/user",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is just begging for confusion. JSON:API does not always appear to be the most concise or obvious thing in the world, so trying to use this as an example here might just complicate the explanation. I'm not sure there.

Are we trying to move the manager info out?

Perhaps a better example would be invoices. People often mix invoices, with payments and payment attempts, and status of those payments as it traces through the bank, which is confusing as fuck.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I agree.

{
"type": "User",
"id": 1,
"attributes": {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you keep this example then maybe split it out into "positions" or "roles" and explain that the extra split is actually a useful feature: you can have multiple roles at the company, you may switch roles, slowly transitin from one to the other with overlap, etc. Usually the extra resources provide extra functionality. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im going to go with the invoice example, seems more straight forward :)


### Wrongly modeled data.

In conjunction with the above, another reason people complain about REST response sizes being so large is that developers have not modeled the data for the requests. Lets consider the example above. In it, we have two requests we are making, ```/api/users``` and ```/api/users/11122```. In the first request, we should return the least amount of data possible. When making the first GET request, which returns all the resources for the given endpoint, model your data to return the bare minimum. In this case, a userId and a name.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have not modeled the data for the requests

not sure what this means

}
```

And that's all you need! Along with hypermedia, the other data is close by but now our response is more concise and easier to use.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could add that "the other benefit to having smaller payloads with links for more data to grab if the client wants it" is "these smaller more targeted resources might be http cached, meaning when your client goes to fetch more data avout crashy's positions, its right there in the HTTP client cache. =Insert link to article=.

categories: jekyll update
---

One of the biggest complaints people have about REST is that the response size is too big. In reality though, that is not a REST problem, that is a problem with the developers maintaining that endpoint. Let's look at some reasons why and how we can mitigate it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh shit very first thing maybe you could say "This argument is a huge misnomer because OData and JSON-API, etc have sparse fieldsets (you can request only the fields you want" which is almost certainly the inspiration for the GraphQL feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants