Error 404 occurs because the specified resource does not exist on the server (or a handler for the resource). 404 errors are not only related to the GET method, but are related to all HTTP methods.
That’s why, even when you created the resource 999.json
on your server, in the path specified, it no longer returns 404 status (I believe it has returned 200).
The problem is therefore in its implementation on the server.
HTTP
In your comment, you said you have nothing on the server.
The HTTP protocol, used in web requests (either HTTP 1, 1.1 or 2), has some access methods. The most used in traditional applications are GET and POST, but with the diffusion of the development of Restful Apis, the PUT and DELETE methods have also been widely used.
These names are not just cute names. They have a semantics. Simply put:
- GET: asks for representation of a particular resource;
- POST: asks the webserver to store the sent data subject to the specified resource (think of it as "changing the resource");
- PUT: asks for data to be stored as the specified resource (think "create a resource");
- DELETE: asks for the resource to be removed.
What is a recurso
? Resource is specified in the URL after the domain and before the fragment and query and identifies "something" on the server. For example:
http://www.dominio.com.br/meu/recurso?consulta=exemplo#fragmento
http://
: schematic;
www.dominio.com.br
: domain;
/meu/recurso
: resource path;
?consulta=exemplo
: consultation;
#fragmento
: fragment.
By default, HTTP does not specify what this "resource" is on the server: it is completely within the domain of your web application. That is, it can be a file, a record in the database, or something much more complex (or simpler).
Similarly, virtually all status codes can be returned by each of these methods. Often, these status also depend on the domain of the application.
That is, a POST request can return a 404 if the resource is not found. A PUT however, is more unusual to return 404, as it is expected that it does not exist on the server and you want to create it.
So the correct thing would be to use PUT in your request? The correct thing would be to use PUT, not POST. But only this will not solve.
HTTP nothing but standardizes the exchange of messages between the client and the server. Web servers, like Nginx, Apache and any other, only implements this message exchange.
It’s up to you to implement how to respond to each of the messages. And it’s up to you to follow the status standards set by HTTP.
But why does GET work? Because when you install the server, you specify a path called DocumentRoot
, which is (simply) a folder in the file system understood as the /
of your resources. All requests that arrive on the server, will be processed relative to this directory. By default, web servers deliver files (GET request) if they exist (status 200), or return error otherwise (404, 403, etc). That’s why when creating the archive 999.json
you now receive a status 200.
But note that, despite everything, your POST requests probably did not change the resource itself. This is because although the resource exists, the server does not know what to do with it.
So what to do? You should implement your resource handler for this feature, and it yes perform due work.
How to do it? Each language is one way, and the chosen server (Apache, etc.) influences the implementation. Jetbeans should be JSP, look in Google. I already did, but I can’t even remember how he created the project. It’s not difficult, and it’s usually a boring and repetitive service.
I hope the explanation has cleared up a bit. Take a look at the Wikipedia page on HTTP (in English). As much as there are countless people out there developing for the web, the vast majority (no doubt!) do everything anyway, do not know the "why". Understanding the protocol (just the basics, calm down!) is the first step to becoming a good developer!
I hope I’ve helped!
you can start your control as an anonymous function instead of:
... function EditEventController($scope, eventData){ ...
, usefunction($scope, eventData) {...
– Ivan Ferrer
Play in a variable before sending the resource. It’s a request order question, I believe. You first get the full url, then you get the request. You can’t do both at the same time... there’s no way you can get an id of something that hasn’t existed yet.
– Ivan Ferrer