Weekly Support, 29th May 2019
Opened this issue Β· 12 comments
Hi all!
Kindly drop in any question on the topic: Building Web Services using Node.js.
We will be joining a Q & A session with 17:00 HRS EAT. Please attend without fail to be able to unlock and unblock your world-class developer potential.
Join Zoom Meeting using https://andela.zoom.us/j/668566256
Hi! Those with issues on the HTTP verbs this link could be useful https://www.restapitutorial.com/lessons/httpmethods.html
Get is used to request data from a specified resource.
while
Put is used to send data to a server to create/update a resource.
also
Post is used to send data to a server to create/update a resource.
What is the difference between a PATCH method and a PUT method?
A PATCH method can be used to update existing information partially in a server , while a PUT method can be used to update it entirely.
For example:
If you have a JSON object with various attributes such as name, age, phone number, and address, you can use PATCH to update just one of them. But if you want to makes changes to all attributes, then you use the PUT method for that.
API response
What
HTTP status codes are standard response codes communicated by the server to the client to tell about a request.
When communicating with the api, we expect to get response in a certain format. Among other parts of the response, one key part is a status code.
A status code is a number that tells us if request has been successfully completed.
You donβt need to know every HTTP status code, but there are important HTTP status codes you must be familiar with
- 1xx Status Codes: Information Request
- 2xx Status Codes: Success
- 3xx Status Codes: Redirection
- 4xx Status Codes: Client Error
- 5xx Status Codes: Server Error
focus more on 2xx and 4xx.
A detailed reference can be found here see Docs and here
Why
There are many reasons to why they are important, here is a few from the top of my head
-
Ease in communication, It is easy for a client to know the status of the request
-
Ease in debugging. Before you start pulling your hair why it doesn't work, first check the code, it will help you narrow down on what went wrong.
Oops my bad @lupyana, I've tried to change it but still getting the same response
Oops my bad @lupyana, I've tried to change it but still getting the same response
Check on how you are assigning the id from request parameter, Just before you return the response. Is that correct?
Did you declare the _id variable?
Oops my bad @lupyana, I've tried to change it but still getting the same response
Check on how you are assigning the id from request parameter, Just before you return the response. Is that correct?
Is that the new syntax of assigning variables?
Can i use get, post, put method in one API file ? or do i need different file for every API method?
1)It is okay if it works but not recommended because of its difficult in maintenance
Imagine passing through many lines of code, find one line and trying to make some changes its difficult. So you could make the code more readable by arranging properly your APIs like implementing it in different file.
2)By using separate file allow for clear and clean separation of different method allowing easier reading and updating document.
See #38
it's working now @lupyana @landrykapela thank you guys