I've been doing a research to figure out a way to implement Standard JSONAPI (https://jsonapi.org) but I didn't find a source of truth or a convincing way to implement this.
to represent this in a real example, we have the following response
{
"data": {
"type": "articles",
"id": "1",
"attributes": {
// ... this article's attributes
},
"relationships": {
// ... this article's relationships
}
}
}
so the expected entities we have are article and maybe author. those entities are stored in Database (SQL or NoSQL) and any tool is used to query the data (Mongoose, Knex, typeorm..etc)
the expected returned result from a database is (select 1st from articles)
{
"name":"article1",
"id":"1"
}
and the question is where is the best place to process the response from DB and transfer it into JSONAPI standard? is it Model layer? Controller? view or add a presentation layer?
I've been thinking about a way to implement this by using a template engine (pug, Handlebars..etc) but is this a good idea? since the template engine target is HTML and not JSON?
in case it is a good idea to use a template engine to render JSON, is there any available JSON template engine to generate JSON?
Any advice or a guide or a well-written example can be looked at?
Thanks.