fabienhenon / jsonapi Goto Github PK
View Code? Open in Web Editor NEWJson API decoder and Encoder
Home Page: http://package.elm-lang.org/packages/FabienHenon/jsonapi/latest
License: BSD 3-Clause "New" or "Revised" License
Json API decoder and Encoder
Home Page: http://package.elm-lang.org/packages/FabienHenon/jsonapi/latest
License: BSD 3-Clause "New" or "Revised" License
Given the following json
{
"data": {
"id": "38",
"type": "question_set",
"attributes": {
"position": 33,
"title": "Goal 2: Zero Hunger"
},
"relationships": {
"form_category": {
"data": {
"id": "6",
"type": "form_category"
}
},
"responses": {
"data": []
},
"form_questions": {
"data": [
{
"id": "43",
"type": "text_area"
},
{
"id": "44",
"type": "text"
}
]
}
},
"links": {
"self": "http://localhost:4000/v1/cops/1/questions/38",
"next_question": "http://localhost:4000/v1/cops/1/questions/44",
"prev_question": "http://localhost:4000/v1/cops/1/questions/32"
}
},
"included": [
{
"id": "6",
"type": "form_category",
"attributes": {
"position": 6,
"title": "SDGs"
},
"relationships": {
"form_questions": {
"data": []
}
}
},
{
"id": "43",
"type": "text_area",
"attributes": {
"position": 4,
"title": "Please use this space to describe in more detail the work you are undertaking to contribute to this Goal"
},
"relationships": {
"form_category": {
"data": {
"id": "6",
"type": "form_category"
}
},
"responses": {
"data": []
}
},
"links": {
"self": "http://localhost:4000/v1/forms/1/questions/43",
"next_question": null,
"prev_question": null
}
},
{
"id": "44",
"type": "text",
"attributes": {
"position": 5,
"title": "Other question type"
},
"relationships": {
"form_category": {
"data": {
"id": "6",
"type": "form_category"
}
},
"responses": {
"data": []
}
},
"links": {
"self": "http://localhost:4000/v1/forms/1/questions/44",
"next_question": null,
"prev_question": null
}
}
]
}
How can I decode the form_questions
relation? I need some way to access the type so I know what decoder to use.
Hi,
I can't figure out how to decode collection level links,
Like in the bellow example:
{
"data": [
{
"id": "1",
"type": "cop",
"attributes": {
"report_period_from": "2018-10-22T10:00:00.000+00:00",
"report_period_to": "2018-10-22T10:00:00.000+00:00"
},
"relationships": {
"form": {
"data": {
"id": "1",
"type": "form"
}
}
},
"links": {
"self": "http://localhost:4000/v1/cops/1",
"current_question": null
}
}
],
"included": [
{
"id": "1",
"type": "form",
"attributes": {
"name": "COP seed"
},
"relationships": {
"form_categories": {
"data": []
}
},
"links": {
"self": "http://localhost:4000/v1/forms/1"
}
}
],
"links": {
"create": "http://localhost:4000/v1/cops"
}
}
I want to grab the create link
Given a link is null
{
"id": "1",
"type": "cop",
"attributes": {
"report_period_from": "2018-10-22T10:00:00.000+00:00",
"report_period_to": "2018-10-22T10:00:00.000+00:00"
},
"relationships": {
"form": {
"data": {
"id": "1",
"type": "form"
}
}
},
"links": {
"self": "http://localhost:4000/v1/cops/1",
"current_question": null
}
}
When decoding this resource the links dictionary is empty, I think it will be better if null links are ignored.
A resource can have a relation that might not be included in the included
node
For example:
{
"data": {
"id": "1",
"type": "cop",
"attributes": {
"report_period_from": "2020-06-15T16:35:49.433+00:00",
"report_period_to": "2021-06-15T16:35:49.433+00:00",
"completed_percent": 28,
"level": "active"
},
"relationships": {
"form": {
"links": {
"self": "http://localhost:4000/cop/1/relationships/formr",
"related": "http://localhost:4000/form/1"
},
"data": {
"id": "1",
"type": "form"
}
}
},
"links": {
"self": "http://localhost:4000/v1/cops/1",
"current_question": "http://localhost:4000/v1/cops/1/questions/1"
}
},
"links": {
"create": "http://localhost:4000/v1/cops"
},
"included": [
]
The cop
type has a form
relationship that is not included in the response, the client can specify to include this resource or it can go fetch it when needed via the related
link.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.