api json method verbs code example

Example 1: http methods

GET 
			getting data in the server 

		POST 

			adding data to the server 

			we need to provide the data in the format 
			the document specify
			and tell exactly what type if data we are sending
			defined by Content-Type Header 

			Common status code for successful POST is 
				201 Created -- you will have response body 

		 PUT 
		 	Put is used to update the exsisting data from the server 
		 	difference between PUT and POST 
		 	 POST is adding new data 
		 	 	so the URL will be /api/spartans
		 	 PUT is updating existing data 
		 	 	so the URL will be /api/spartan/validIDNumberHere

		 	 provide updated data 
		 	 provide the contenttype of the data you are sending to update 

		 	 common status code for successful PUT request
		 	  is 204 NO-CONTENT , it has no response body 
		 	  204 means it was updated successfully 


		  DELETE 

		  	Delete method is used to delete the data from the server
		  	Request URL will  /api/spartan/theValidID

		  	common status code for successful Delete request
		 	  is 204 NO-CONTENT , it has no response body 
		 	  204 means it was deleted successfully

Example 2: types of method in api

GET	is used for reading and retrieving data.
POST	is used for inserting data.
PUT	is used for updating data.
DELETE	is used for deleting data.

The primary or most-commonly-used HTTP verbs (or methods, as they are properly called) are POST, GET, PUT, PATCH, and DELETE. These correspond to create, read, update, and delete (or CRUD) operations, respectively.

Tags:

Misc Example