API and Web Service
API
API - Application Programming Interface
Letter
Word
Meaning
A
Application
Software that does a task
P
Programming
Program (P) that does the task in the Application (A)
I
Interface
Place (I) to tell the program (P) to run
API Definition: You tell (I) a program (P) to run in an application (A)
Level od Difficulty
Example
I (Interface)
P (Program)
A (Application)
Simple
Messenger message using smartphone
smartphone
message
Messenger
Simple
Google search using computer
computer
search
Moderate/Complex
Create orders in Amazon (in system)
Amazon
create orders
Amazon
How API works
Request
Program
Response
![](https://tester-bszelag.gitbook.io/~gitbook/image?url=https%3A%2F%2F4075407169-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-MCCXrRYTXdf78GMukgv%252F-MEbnm-3EYZLZmnq10XC%252F-MEbs0U82SO-EC7cX_GB%252FAPI_Scheme.jpg%3Falt%3Dmedia%26token%3Da9b5b2f3-c0b7-42c6-bfac-3fa6363607d9&width=768&dpr=4&quality=100&sign=e258c960&sv=2)
We type any search to www.google.com like "wikipedia"
Press Enter > Request is send to google Server
A program "/search" is run
Send by response our results of searching
www.google.com/search?q=wikipedia
/search -> folder on www.google.com server ?q=wikipedia -> our search parameter
Web Service
Web -> internet Service -> API Web Service -> API that uses the internet
Web Service
API
All web services are APIs.
All APIs are not web services.
It supports XML.
Responses are formatted using Web API's MediaTypeFormatter into XML, JSON, or any other given format.
You need a SOAP protocol to send or receive and data over the network. Therefore it does not have light-weight architecture.
API has a light-weight architecture.
It can be used by any client who understands XML.
It can be used by a client who understands JSON or XML.
Web service uses three styles: REST, SOAP, and XML-RPC for communication.
API can be used for any style of communication.
It provides supports only for the HTTP protocol.
It provides support for the HTTP/s protocol: URL Request/Response Headers, etc.
the difference i just copy from
HTTP
HTTP - Hypertext Transfer Protocol
http(s)
://www.google.com
Parts of HTTP
HTTP
Request
Response
Start line
Version HTTP/1.1, Method (GET/POST...),API program location, parameters...
Version HTTP/1.1, Status Code (200 OK)
HEADERS
Host: www.google.com
Token: xxxxxx (API token)
Cookie: xxx
Cookie: xyz...
HTML
Blank line
(just separator of HEAD and BODY)
(just separator of HEAD and BODY)
BODY
When use POST by registration Username and Password
HTML
Start line
Request
Response
Name
Start line, Request line
Start line, Response line
HTTP Version
HTTP/1.1
HTTP/1.1
Method
GET, POST, PUT, DELETE, ...
No
API Program Folder Location
Yes (example: /search)
No
Parameters
Yes (example: ?q=wikipedia)
No
Status Code
No
Yes (example: 200 OK)
Format
Method (space) API Program Folder Location+Parameters (space) HTTP Version
HTTP Version + Status Code
Example
GET /search?q=wikipedia(optional) HTTP/1.1
HTTP/1.1 200 OK
Headers
Blank line
There is where head end and body beginning.
Body
HTTP Methods
The most popular are GET, POST, PUT, DELETE like in database CRUD (Create, Read, Update, Delete)
HTTP methods
Description
GET
Read (get data from server)
POST
Create (post data into server)
PUT
Update (put file into server)
DELETE
Delete (delete the object at the location)
HEAD
TRACE
OPTIONS
CONNECT
PATCH
HTTP Status Codes
The groups of HTTP status codes:
1xx Informational response
2xx Success
200 OK 201 Created
3xx Redirection
4xx Client errors
400 Bad Request 404 Not Found
5xx Server errors
500 Internal Server Error 502 Bad Gateway
JSON
Nowadays is more populary than XML
JSON -> JavaScripts Object Notation
HTTP Header Line: Content-Type: application/json HTTP Body: JSON JSON uses "Key" : "Value" (e.g. "Fruit" : "Apple")
To show how JSON works i used online editor:
![](https://tester-bszelag.gitbook.io/~gitbook/image?url=https%3A%2F%2F4075407169-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-MCCXrRYTXdf78GMukgv%252F-MEcz17aYa9J_YJe_IJ2%252F-MEd-rDGFg9ry7zUjMuB%252Fimage.png%3Falt%3Dmedia%26token%3Df500ce9e-a9e6-4e2c-8fc3-c3ea50841622&width=768&dpr=4&quality=100&sign=216d25dd&sv=2)
![](https://tester-bszelag.gitbook.io/~gitbook/image?url=https%3A%2F%2F4075407169-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-MCCXrRYTXdf78GMukgv%252F-MEcz17aYa9J_YJe_IJ2%252F-MEd0FkOyQmyjCjSc7fg%252Fimage.png%3Falt%3Dmedia%26token%3Df69e96e4-d01d-4ca7-b1ec-558ed7ec6663&width=768&dpr=4&quality=100&sign=dba5745d&sv=2)
Mozilla Firefox could open .JSON file without any extension
XML
XML -> eXtensible Markup Language
HTTP Header Line: Content-Type: application/xml HTTP Body: XML XML uses tags <> (e.g. <button>Click Me!</button>)
![](https://tester-bszelag.gitbook.io/~gitbook/image?url=https%3A%2F%2F4075407169-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-MCCXrRYTXdf78GMukgv%252F-MEcdL0T2POTWOhFAcgH%252F-MEcsUNURL96FfbK4N0l%252Fimage.png%3Falt%3Dmedia%26token%3D8f8245e8-a45a-4e48-aced-34e79f56e78e&width=768&dpr=4&quality=100&sign=21121d2&sv=2)
REST
Nowadays is more populary than SOAP
REST -> Representational State Transfer
REST is used to complete a Web Service (API) using HTTP
4 HTTP Request Parts Start line All Methods (GET, POST, PUT, DELETE, ...) Header Line All Blank Line Body Any (JSON, XML, html, images, ...)
SOAP
SOAP -> Simple Object Access Protocol
SOAP uses a WSDL (Web Service Description Language)
4 HTTP Request Parts Start line POST WSDL HTTP Version Header Line Content-Type: text/xml Blank Line Body XML envelope formed using WSDL
Browser DevTools
GoogleChrome F12 MozillaFirefox F12 Opera Ctrl+Shift+C
Last updated
Was this helpful?