I am trying to make REST calls from an angular program that I wrote. I am using JSON Server as the back end. (https://jsonplaceholder.typicode.com/) I created a db.json file which I am serving.
GET and PUT work but DELETE and POST do not – I get a return code of 404… I can GET the resource that I am trying to DELETE at the same location in the code.
I would like to upload my html, js, and css files, but this editor is not allowing these file types. Is there a way I can upload these files here?
You should either link to the files somewhere (CodePen, GitHub, etc), or just post the relevant code formatted in markdown. Check out this post to see how to format code properly on the forum. Also, what kind of response are you getting when you try to POST and DELETE?
Lines 69 and 79 differ from the other URLs you defined. I’m not sure what you need to be targeting, but double check those. Are you getting any errors on the server side?
I want to delete the first object in the db.json file. (There are 6 endpoints at the moment in the file being served.) Even this is not working. Once this works, I will pass an index to this function as I do for the update method. I am getting a 404 on the server side.
By the way, how do you display line numbers on a pen?
I see, the 0 is a hard coded index to delete. I get the feeling that there’s something wrong with the server rather than your front end code. As for the line numbers, they should be displayed on CodePen by default (I don’t think there’s a way to disable them), but they’re very dark and easy to miss.
This server expects a certain structure for the data in db.json. I followed their structure and was able to both POST and DELETE. [I need to change my front end now to correspond to their structure.]
There are line numbers on my pen, but it is very hard for me to read them.