HTTP Response Codes in Mule 4
When you are working with an application and suddenly an error occurs the console page displays a message that tells you about the root cause of the crash.
Join the DZone community and get the full member experience.
Join For FreeWhen you are working with an application, especially a Mule application and suddenly an error occurs, then the console page displays a message that tells you about the root cause of the crash. Have you ever wondered how such messages are generated and shown to us? Is there any physical presence of a human to keep track of the requests and the application pages? Certainly not! Because it is hard to keep logging each request every second.
To handle this situation, HTTP response codes are used. These are in-built codes that are used mainly in creating an application. It also has great importance in Mule 4 because it helps handle the requests. Mule applications use codes while writing RAML code in the design center.
Let us drive deep into the response codes that we come across.
HTTP Response Codes
HTTP codes are helpful to know the status of the request sent to the application. There are around five different types of HTTP response codes.
- Successful response codes
- Server error response codes
- Client error response codes
- Redirection response codes
- Information response codes
Successful Response Codes
When we submit a request, and the request is done successfully then we get a 2XX series response code.
- 200 OK: This means the request is sent and the response is successful.
- 201 Created: This means a request is sent and a new resource or object is created.
- 202 Accepted: Here the request is sent but action is still pending.
Server Error Response Codes
If the error is from the server side, then you will receive a 5XX series response code.
- 500 Internal Server Error: The error occurs when the server has encountered a situation where it can't handle it.
- 502 Bad Gateway: When the server is working as a gateway to get a response we get an invalid response.
- 504 Gateway Timeout: When the server is acting as a gateway and cannot get a response in time.
- 505 HTTP Version Not Supported: This occurs when the HTTP method is not supported.
Client Error Response Codes
If the error is from the client, you will receive a 4XX series response code.
- 405 Bad Request: The server can't process the request due to the error caused by the client side.
- 401 Unauthorised: This means that the response is unauthenticated. The client must first authenticate itself to get the response.
- 403 Forbidden: Here the client does not have access rights to access the content so the server is not allowing it to give the requested resource.
- 404 Not Found: This is displayed when the server cannot find the requested resource.
Redirection Response Codes
If the URL is unable to load or not working, then you will get a redirection response code of series 3XX.
- 301 Moved Permanently: This means the URL of the requested resource has been changed permanently.
- 302 Found: This means the requested resource is present or found.
- 304 Not Modifies: It tells the client that the response has not been modified.
Information Response Codes
The information about a page or application is generally given by the 1XX response codes.
- 100 Continue: This tells the client to continue the request or ignore the response when the request is already finished.
Conclusion
The above response codes are most used in Mule 4 while creating the Mule application. I hope you enjoyed reading this blog. Please do like and comment on your views on today's topic. Happy learning!!
Do check my previous blogs on system integration using Mulesoft:
Published at DZone with permission of Amrutha TESR. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments