reyesoft / ngx-jsonapi

JSON API client library for Angular 5+ 👌 :: Production Ready 🚀
https://ngx-jsonapi.reyesoft.com/
MIT License
101 stars 52 forks source link

New requests sends empty ID string. #123

Closed peavers closed 6 years ago

peavers commented 6 years ago

I've noticed when calling new() you're sending a empty string along with the ID attribute. This goes against the specification and causes headaches on servers expecting nothing.

For example, using a Spring boot backend and Mongo as the datastore, saving the payload will result in the object having "" as it's ID, rather than mongo generating a new one.

See http://jsonapi.org/format/#crud-creating, specifically:

A server MAY accept a client-generated ID along with a request to create a resource. An ID MUST be specified with an id key, the value of which MUST be a universally unique identifier.

A empty string isn't a UUID ;)

pablorsk commented 6 years ago

You're right. We should remove the ID attribute before creating if it is empty.