JSON:API consumption in Rails

Jasiek Matusz
May 6 · 4 min read

Shortcoming

Innovation

POST /photos HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
"data": {
"type": "photos",
"attributes": {
"title": "Ember Hamster",
"src": "http://example.com/images/productivity.png"
},
"relationships": {
"photographer": {
"data": { "type": "people", "id": "9" }
}
}
}
}
{
"photo_parameters": {
"title": "Ember Hamster",
"src": "http://example.com/images/productivity.png",
"photographer": { "id": 9 }
}
}

JsonApi::Parameters

params.require(:photo).permit(photographer: [:id])
params.from_jsonapi.require(:photo).permit(photographer: [:id])

Resources

Visualitypl

Visuality is a Ruby on Rails & React.js full-stack software house founded in 2007. We hire the best software engineers, project managers, and UX/UI designers to ensure maximum reliability, extensibility, changeability, robustness, and maintainability of the custom solutions

Thanks to Grzegorz Korzeniowski.

Jasiek Matusz

Written by

Programmer, gamer. Fan of Ruby and Golang.

Visualitypl

Visuality is a Ruby on Rails & React.js full-stack software house founded in 2007. We hire the best software engineers, project managers, and UX/UI designers to ensure maximum reliability, extensibility, changeability, robustness, and maintainability of the custom solutions