Problems with REST POST and DELETE Calls [SOLVED]

Problems with REST POST and DELETE Calls [SOLVED]
0

#1

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?

Problems with REST POST and DELETE Calls


#2

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?


#3

I am getting a 404 when I try to POST or DELETE. I will post the code using one of the suggested ways.


#4

The above pen contains my code that does NOT work for DELETE and POST.


#5

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?


#6

Line 69:

var root = 'http://localhost:3000/0';

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?


#7

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.


#8

PortableStick:

You are right on both points above…

  1. 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.]

  2. There are line numbers on my pen, but it is very hard for me to read them.

Thanks.