Skip to main content

REST Api

Webservice

        It is communicating between different platforms, different operating systems or different devices by using World Wide Web.
        e.g. mobile and web. Suppose the user has registered on Facebook or Gmail on the website. Now he wants to use a mobile app. So it is not required to register again as we have already registered. We can use the same details for login on mobile as well as the website. It can be possible by using web services. App sends a request to a server and gets a response in JSON or XML format from server.
API - application program interface

There are two types of web services:
1.SOAP
2.REST

SOAP - Simple Object Access Protocol

It gets a response in XML format. It is platform independent and language independent. By using SOAP, you will be able to interact with other programming language applications.

REST - Representational State Transfer

        REST is an architecture for client-server communication. It sends an HTTP request to server and server send a response in JSON format. JSON means Javascript Object Notation. It is an object with key-value pair. e.g. {name: "Abc"mobile: '9876543210', email: "abc@gmail.com"}
Methods involve in REST API are 
  • POST
  • GET
  • PUT
  • DELETE
  • PATCH
POST is used to create a resource e.g. register a user 
GET is used to retrieve a resource When we need details of a particular user. Here we need to send userid or mobile no through URL. So we can fetch data using that id or mobile.
PUT is used to update or create a resource. If the user is already registered then updates his record otherwise create a new record.
DELETE is used to delete a resource
PATCH is used to update a resource partially. When we need to update the user's status only





Comments

Post a Comment

Popular posts from this blog

.htaccess file

What is .htaccess file? A .htaccess file is an ASCII file. It is a short form of  Hypertext Access. It is a configuration file used by Apache-based web servers . The  .htaccess is the file’s extension. It is not a file  name.  It will affect on the folder  in which it is located and also on subfolders. we can use .htaccess for following Remove file extension Redirect to custom error pages Block or allow IP addresses Prevent directory listings How to remove .php extension from URL? Create .htaccess file in root of your project and add following code in it RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php Before  URL is like www.example.com/home.php After adding .htaccess it will be like www.example.com/home Redirect to custom error pages It is used to redirect the user to a custom error page by using the error code. Following are error codes 400 – Bad reque...

Form submit using AJAX

AJAX = Asynchronous JavaScript And XML     AJAX is a client-side script which is used to communicate to the server.  It is used to get or submit the data or update the part of the webpage without refresh the page.  When we want to submit a form, first we get the form data using serialize method following code:- var datastring = $("#create-from").serialize(); If want to send custom data then, var datastring = {name:"ABC",email:"abc@gmail.com"} Now we will submit the form data using ajax $.ajax({      type:'POST',      url:'asySubmit.php',      data:datastring,      beforeSend: function(){                         $('.loader').show();      },      success:function(response) {              console.log(response);      },     ...