angular2-jsonapi
angular2-jsonapi copied to clipboard
Support for using IRI's as ID
When using api platform in combination with json-api, all id's are returned as IRI (Internationalized Resource Identifier). This means that ID's look like "/type/{id}" (example: /forms/1) Trying to delete a record using this IRI results in a requests being made to {baseUrl}/forms//forms/1
Could this be implemented as a config option, or am I doing something wrong?
example GET output from api:
{
"data": {
"id": "/forms/1",
"type": "Form",
"attributes": {
"title": "Form 1",
"description": "An example form",
"_id": 1
},
"relationships": {
"questions": {
"data": [
{
"type": "Question",
"id": "/questions/3"
},
{
"type": "Question",
"id": "/questions/4"
}
]
}
}
}
}
Workaround:
Create a base model, from which all other models are derived. By overriding the default id attribute and loading it from _id we can access the raw id in attributes._id using {model}.id
import {JsonApiModel, Attribute} from 'angular2-jsonapi';
export class BaseModel extends JsonApiModel {
// This allows accessing the raw ID instead of the IRI
@Attribute({serializedName: '_id'})
id: string;
}
Although the workaround means I can access the id, this still means relationships are not loaded. Because all relations are also identified by and IRI they are seemingly ignored.