0% found this document useful (0 votes)
5 views

Rest API

The document provides an overview of APIs, specifically focusing on REST and SOAP APIs, their methods, and components. It explains the differences between HTTP methods like GET, POST, PUT, and PATCH, as well as the advantages and disadvantages of RESTful web services. Additionally, it covers HTTP status codes, the concept of statelessness, and tools like Postman for API testing.

Uploaded by

Gaikwad Nikhil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Rest API

The document provides an overview of APIs, specifically focusing on REST and SOAP APIs, their methods, and components. It explains the differences between HTTP methods like GET, POST, PUT, and PATCH, as well as the advantages and disadvantages of RESTful web services. Additionally, it covers HTTP status codes, the concept of statelessness, and tools like Postman for API testing.

Uploaded by

Gaikwad Nikhil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1. What exactly API means?

application programming interface


API stands for application programming interface, which is a set of definitions and protocols for building and integrating
application software.
APIs are used to integrate new applications with existing software systems. This increases development speed because each
functionality doesn't have to be written from scratch. You can use APIs to leverage existing code.

2. what are the http methods supported by rest api


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.

3. The GET Method and POST Method


GET is used to request data from a specified resource.
• GET requests can be cached
• GET requests remain in the browser history
• GET requests can be bookmarked
• GET requests should never be used when dealing with sensitive data
• GET requests have length restrictions
• GET requests are only used to request data (not modify)

The POST Method


POST is used to send data to a server to create/update a resource.
• POST requests are never cached
• POST requests do not remain in the browser history
• POST requests cannot be bookmarked
• POST requests have no restrictions on data length

4. Difference Between PUT and PATCH Request

S.No. PUT PATCH

1 PUT is a technique of altering resources when PATCH is a technique for transforming the resources
the client transmits data that revamps the whole when the client transmits partial data that will be
resource. updated without changing the whole data.

2 The PUT HTTP method is known to be The PATCH HTTP method is believed to be non-
unchanged. That means, if you retry a request idempotent. That means, if you retry the request
numerous times, that will be equal to a single multiple times, you will end up having multiple
request conversion. resources with different URIs.

3 The PUT method has high bandwidth. Whereas, the PATCH method has comparatively low
bandwidth.

5. Differences between PUT and POST in REST APIs


Here is the important difference between PUT and POST method:
PUT POST
This method is idempotent. This method is not idempotent.
PUT method is call when you have to modify a single POST method is call when you have to add a child resource
resource, which is already a part of resource collection. under resources collection.
RFC-2616 depicts that the PUT method sends a request for This method requests the server to accept the entity which is
an enclosed entity stored in the supplied request URI. enclosed in the request.
PUT method syntax is PUT /questions/{question-id} POST method syntax is POST /questions
PUT method answer can be cached. You cannot cache PUT method responses.
PUT /vi/juice/orders/1234 indicates that you are updating a POST /vi/juice/orders indicates that you are creating a new
resource which is identified by “1234”. resource and return an identifier to describe the resource.
If you send the same request multiple times, the result will If you send the same POST request more than one time, you
remain the same. will receive different results.
PUT works as specific. POST work as abstract.
We use UPDATE query in PUT. We use create query in POST.
In PUT method, the client decides which URI resource In POST method, the server decides which URI resource
should have. should have.

6. What is REST API


Representational State Transfer (REST) is an architectural style that defines a set of constraints to be used for creating web
services. REST API is a way of accessing web services in a simple and flexible way without having any processing.

7. what do you mean by soap api and why is it used


Simple Object Access Protocol (SOAP) is a message specification for exchanging information between systems and
applications. When it comes to application programming interfaces (APIs), a SOAP API is developed in a more structured
and formalized way.

8. SOAP vs REST
The term web API generally refers to both sides of computer systems communicating over a network: the API services
offered by a server, as well as the API offered by the client such as a web browser.
The server-side portion of the web API is a programmatic interface to a defined request-response message system, and is
typically referred to as the Web Service. There are several design models for web services, but the two most dominant are
SOAP and REST.
SOAP provides the following advantages when compared to REST:
• Language, platform, and transport independent (REST requires use of HTTP)
• Works well in distributed enterprise environments (REST assumes direct point-to-point communication)
• Standardized
• Provides significant pre-build extensibility in the form of the WS* standards
• Built-in error handling
• Automation when used with certain language products
REST is easier to use for the most part and is more flexible. It has the following advantages when compared to SOAP:
• Uses easy to understand standards like swagger and OpenAPI Specification 3.0
• Smaller learning curve
• Efficient (SOAP uses XML for all messages, REST mostly uses smaller message formats like JSON)
• Fast (no extensive processing required)
• Closer to other Web technologies in design philosophy

9. HTTP Status Codes


What are HTTP status codes?
An HTTP status code is a server response to a browser’s request. When you visit a website, your browser sends a request to
the site’s server, and the server then responds to the browser’s request with a three-digit code: the HTTP status code.
The first digit of each three-digit status code begins with one of five numbers, 1 through 5; you may see this expressed as
1xx or 5xx to indicate status codes in that range. Each of those ranges encompasses a different class of server response.
Common HTTP status code classes:
1xxs – Informational responses: The server is thinking through the request.
2xxs – Success! The request was successfully completed and the server gave the browser the expected response.
3xxs – Redirection: You got redirected somewhere else. The request was received, but there’s a redirect of some kind.
4xxs – Client errors: Page not found. The site or page couldn’t be reached. (The request was made, but the page isn’t valid
— this is an error on the website’s side of the conversation and often appears when a page doesn’t exist on the site.)
5xxs – Server errors: Failure. A valid request was made by the client but the server failed to complete the request.

HTTP Status Code 200 - OK


This is your ideal status code for your normal, everyday, properly functioning page.
HTTP Status Code 301 - Permanent Redirect
A 301 redirect means that visitors and bots that land on that page will be passed to the new URL.
HTTP Status Code 302 - Temporary Redirect
A 302 redirect is similar to a 301 in that visitors and bots are passed to the new page, but link equity may not be passed
along.
HTTP Status Code 404 - Not Found
This means the file or page that the browser is requesting wasn’t found by the server.
HTTP Status Code 410 - Gone
A 410 is more permanent than a 404; it means that the page is gone. The page is no longer available from the server and no
forwarding address has been set up.
HTTP Status Code 500 - Internal Server Error
Instead of the problem being with pages missing or not found, this status code indicates a problem with the server.
HTTP Status Code 503 - Service Unavailable
Another variety of the 500, a 503 response means that the server is unavailable. Everyone (human or otherwise) is asked to
come back later.

10. What are the main components in HTTP request and response?
An HTTP request is divided into three parts: Request line, header and body.

11. What are the main components in HTTP response?


An HTTP response is also divided into three parts: Status line, header and body.

12. Can we use get/post method instead of put method to create resource?
Since both can be used to submit data, you can use either POST or PUT to create or update a resource.

------------------------------------------------------------------------------------------------------------------------------------

13. what is restful web services? what are its features?


RESTful Web Services are basically REST Architecture based Web Services. In REST Architecture everything is a resource.
RESTful web services are light weight, highly scalable and maintainable and are very commonly used to create APIs for web-
based applications.

14. What are disadvantages of REST web services?


Some of the disadvantages of REST are :
* Sessions can’t be maintained.
* Since it works on HTTP, there can’t be asynchronous calls.
* Since there is no contract defined between service and client, it has to be communicated through other means such as
documentation or emails.

15. what is payload in terms of restful web services


The payload of an API is the data you are interested in transporting to the server when you make an API request. Simply
put, it is the body of your HTTP request and response message.

16. is it possible to send payload in the get and delete methods


Not forbidden, but it's unusual to send a payload with GET and DELETE methods. There can be some client libraries that do
not support the payload with these two methods. It's also possible that some servers may just ignore the body of GET and
DELETE methods. It's better not to include payload with these two methods.

17. maximum payload size for post method?


The POST method itself does not have any limit on the size of data. There is no limit according to the HTTP protocol itself,
but implementations will have a practical upper limit. I have sent data exceeding 4 GB using POST to Apache, but some
servers did have a limit of 4 GB at the time.

18. which markup language can be used in restful web api


There are only two markup languages that can be used in a RESTful web API. List them, briefly. Example: "XML and JSON are
two markup languages that can be used in a RESTful web API."

19. XML vs JASON

The Basis Of JSON XML


Comparison
Applicability To transmit the data in a parseable To have the data in a structured way,
manner via the internet. which the user can use to annotate
metadata, parse the scripts.

Code representing { <Document>


objects “Paragraphs”: [ <Paragraph Align = “Center”>
{ Here <Bold> is </Bold> some text
“align”: “center”, </Paragraph>
“content”: [ </Document>
“Here “, {
“style”: “bold”,
“content”: [“is”] },
“some text.”
]}
]}

Representation of { <Person>
Hierarchy elements “firstName”: “Mr.”, <FirstName>Mr</FirstName>
“lastName”: “A” <LastName>A</LastName>
“details”: [“Height”, “Weight”, “Color”, <Details>
“Age”, “Sex”, “Language”] } <Details>Height</Details>
<Details>Weight</Details>
<Details>Color</Details>
<Details>Age</Details>
<Details>Sex</Details>
<Details>Language</Details>

Popularity reason JSON is less verbose and faster. XML uses more words to describe the
intention. Sometimes it is more than
necessary. Parsing XML software is a
slow and tedious job. This costs in
terms of memory consumption.

Data structure JSON data structure is a map. The map XML is a tree. Means a tree
is similar to key/value pairs and is representation of data. This makes
useful when interpretation and working on XML a tedious and time-
predictability are needed. consuming task.

Data Information JSON is preferred for data delivery XML is preferred for storing information
between servers and browsers. on the server side.

Browser-Side – Server JSON is preferred. XML is preferred.


Side

Metadata tagging Putting metadata in the tags is one of In JSON, this is achieved; look how –
the crucial factors XML leads to JSON. The programmer has to make the entity
This is how – This is simple for XML an object; after this, the attribute has to
using attributes. be added as a member of an object.
The point of concern here is the way of
doing this process.

Mixed content Strings are there which contain Considering the JSON, things are pretty
structured markup. Handling this in complex as JSON only contains data. In
XML is easier yet effective. In this doing this, a programmer has to store
process, a programmer has to put the metadata as data again. This adds
marked-up text within a child tag of complexity to the process.
the parent to which it belongs.

20. what is resource in rest api what is the way to represent it


A resource in REST is a similar Object in Object Oriented Programming or is like an Entity in a Database. Once a resource is
identified then its representation is to be decided using a standard format so that the server can send the resource in the
above said format and client can understand the same format.

21. what is the benefit of using rest in web api


1. Lightweight
One of the main benefits of REST APIs is that they rely on the HTTP standard, which means it’s format-agonistic and you can
use XML, JSON, HTML, etc. This makes REST APIs fast, and lightweight — which is necessary for mobile app projects,
internet of things devices, and more.
2. Independent
Another benefit of REST APIs is the fact that the client and server are independent. In other words, the REST protocol
separates the data storage and the UI from the server. This means that developers can work on different areas of a project
independently and try out multiple developer environments as needed.
3. Scalable and flexible
One of the third benefits of REST APIs, and perhaps one of the most important, is scalability and flexibility . REST APIs can
be scaled quickly primarily due to the separation between the client and the server. Additionally, developers can also easily
integrate REST APIs without much added work.

22. what is the concept of statelessness in rest api


Stateless: REST APIs are stateless, meaning that calls can be made independently of one another, and each call contains all
of the data necessary to complete itself successfully.

23. What is meant by URI?


A URI — short for “Uniform Resource Identifier” — is a sequence of characters that distinguishes one resource from
another. For example, foo://example.com:8042/over/there?name=ferret#nose is a URI containing a scheme name,
authority, path, query and fragment. A URI does not need to contain all these components.

24. what is cors in rest api


Cross-origin resource sharing (CORS) is a browser security feature that restricts cross-origin HTTP requests that are initiated
from scripts running in the browser.

25. what do you mean by postman and why do we use it


Postman is a standalone software testing API (Application Programming Interface) platform to build, test, design, modify,
and document APIs. It is a simple Graphic User Interface for sending and viewing HTTP requests and responses.

You might also like