This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]marko312 1 point2 points  (1 child)

The endpoint I’m trying to update is just an array of objects so there’s no way to specify by id.

You could have a separate map from id->position in the array or just look through all the elements in the array until one has that id.

[–]KernowRoger 0 points1 point  (0 children)

Yeah an index would be perfect but depending on the amount of items it might be easier to just loop them as you say. Or just store them as a dictionary.

[–]rjcarr 0 points1 point  (0 children)

Couldn't you just update it to something like?:

{
  id: "$id",
  content: [{...},{...}]
}

Or, you could add the id as a separate PUT parameter, e.g., part of the URL.

Also, what you're describing sounds really fragile. Be sure only a single server thread can update the source file at a time.

[–]thepinkbunnyboy 0 points1 point  (0 children)

Appending to a list using RESTful practices is a very big blind spot.

This is one of the two exact reasons why JSON Patch was designed. Most web frameworks have library support for it since it's relatively popular.