Use of "type" parameter in Resource Objects

Under JSON:API — Latest Specification (v1.0) it says, that any POST-request MUST include a single Resource-Object JSON:API — Latest Specification (v1.0).

The question is, is there a propper use for the type parameter of the resource-object in a POST-request

It clearly indicates the type of resource to create. While some collections are homogeneous, and the examples in the specification appear to follow that pattern, that’s not required by JSON:API.

It’s also worth noting that nothing make the homogeneity of a collection directly discoverable via JSON:API. Therefore, it’s best for the client to always be explicit about expectations. In the case of a homogeneous collection, the type in the POSTed resource object allows the server to verify that the client’s expectation matches what the server is willing to provide: if the type doesn’t correlate with what’s allowed for the collection, an appropriate error can be returned.

-Fred

1 Like