Answer the question
In order to leave comments, you need to log in
How to control the integrity and sufficiency of data on the client?
I will take an example for the question from the JSON API documentation, but this is not important. the same questions will arise when working with other conventions, such as GraphQL.
Suppose I need to get a list of articles with data about their authors.
I make a request according to the JSON API documentation with a field request:
GET /articles?include=author&fields[articles]=title,body,author&fields[people]=name HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/vnd.api+json
{
"data": [{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!",
"body": "The shortest article. Ever."
},
"relationships": {
"author": {
"data": {"id": "42", "type": "people"}
}
}
}],
"included": [
{
"type": "people",
"id": "42",
"attributes": {
"name": "John"
}
}
]
}
{
articles: {
"1": {
id: "1",
title: "JSON API paints my bikeshed!",
body: "The shortest article. Ever",
author: "42"
}
},
people: {
"42": {
name: "John"
}
}
}
Answer the question
In order to leave comments, you need to log in
Here is my version so far:
1. Create a single action (redux) for all data requests via the API
2. Each component that launches the action always launches it when the component is inserted into the DOM and be sure to pass a scheme to it that describes the structure of the data needed by the component
3. The action (has access to the store) checks all the fields of all the necessary resources for compliance with the schema, if all the fields exist - ok, then the component is rendered, if not, then the component lacks all or part of the data, a GET request is generated for the required fields and sent to the server
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question