Stream: students
Topic: API Create
MarenG (Aug 01 2017 at 16:33):
Hello,
does anyone know whether it is possible to specify the ID when creating a resource using the REST-API? If so, how?
Somehow, you can do it with the public HAPI-server, but when looking at the corresponding actual Request (including header and body) I cannot find the ID anywhere.
Thanks for any thoughts on that.
Lloyd McKenzie (Aug 01 2017 at 22:37):
If you use PUT, you can specify the id - if the server supports that.
MarenG (Aug 02 2017 at 10:09):
If you use PUT, you can specify the id - if the server supports that.
How exactly do I specify the ID? Just by adding it to the resource in the body?
And how can I alter the server to support that? Do you have a link to the source code or something?
Thanks!
Lloyd McKenzie (Aug 02 2017 at 14:25):
You'll PUT to that URL. E.g. PUT [somebase]/Patient/123
Lloyd McKenzie (Aug 02 2017 at 14:25):
(Though the id needs to be present inside the resource too.)
Lloyd McKenzie (Aug 02 2017 at 14:26):
If the server doesn't support it, you can't do it. If you're using one of the open source servers, which one are you using?
John Moehrke (Aug 02 2017 at 15:07):
If Lloyd has not made it clear enough... a client specifying the id on -create- is very unusual. Certainly NOT "RESTful". There might be good reason, but they are unusual.
MarenG (Aug 02 2017 at 16:07):
Ok, thanks :)
I have created a bunch of resources in JSON and want to put them on the server, but when the IDs are assigned randomly by the server, I have almost no chance to ensure that my scenario I have built stays intact.
Grahame Grieve (Aug 02 2017 at 20:52):
it's not unusual to just PUT to the location you want the content to live in. Allowing the client to do this can create issues, but is certainly a common thing to do - gets more common as the ecosystem narrows
Last updated: Apr 12 2022 at 19:14 UTC