json-api-php / json-api

Implementation of JSON API in PHP
https://json-api-php.github.io/
MIT License
183 stars 18 forks source link

Omitting id in ResourceObject #107

Open cincauhangus opened 4 years ago

cincauhangus commented 4 years ago

Is it possible to omit the id in ResourceObject when making a request to create a new resource? From the JSON API spec, it allows id to be omitted when creating resources.

f3ath commented 4 years ago

Good point. Looks like a missing feature.

f3ath commented 4 years ago

Implemented in #108. Please take a look at v2.2.0 and let me know if that works for you.

Example: https://github.com/json-api-php/json-api/blob/master/test/NewResourceObjectTest.php

cincauhangus commented 4 years ago

thank you, will check it out in a bit!

cincauhangus commented 4 years ago

I've tested it out and I believe it would work for a typical insert operation. However, I realised my current code is also not per spec as well as I have multiple new resources in the data object, e.g.

{
    data: [
        { /*new resource*/ },
        { /*new resource*/ }
    ]
}

I believe the correct method is to adopt the atomic extension. Do you have plans to support this extension?

f3ath commented 2 years ago

No such plans, but PRs are always welcomed. (I know, I'm super fast with my replies)