Web APIs

Web APIs

REST (Representational State Transfer) APIs

Example:

GET /users/123

SOAP (Simple Object Access Protocol) APIs

Example:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:GetStockPrice>
         <tem:StockName>AAPL</tem:StockName>
      </tem:GetStockPrice>
   </soapenv:Body>
</soapenv:Envelope>

GraphQL

Example:

query {
  user(id: 123) {
    name
    email
  }
}

Advantages of Web APIs

Web APIs vs Web Servers

Feature Web Server API (Application Programming Interface)
Purpose Primarily designed to serve static content (HTML, CSS, images) and dynamic web pages (generated by server-side scripts). Primarily designed to provide a way for different software applications to communicate with each other, exchange data, and trigger actions.
Communication Communicates with web browsers using the HTTP (Hypertext Transfer Protocol). Can use various protocols for communication, including HTTP, HTTPS, SOAP, and others, depending on the specific API.
Data Format Primarily deals with HTML, CSS, JavaScript, and other web-related formats. Can exchange data in various formats, including JSON, XML, and others, depending on the API specification.
User Interaction Users interact with web servers directly through web browsers to view web pages and content. Users typically do not interact with APIs directly; instead, applications use APIs to access data or functionality on behalf of the user.
Access Web servers are usually publicly accessible over the internet. APIs can be publicly accessible, private (for internal use only), or partner (accessible to specific partners or clients).
Example When you access a website like https://www.example.com, you are interacting with a web server that sends you the HTML, CSS, and JavaScript code to render the web page in your browser. A weather app on your phone might use a weather API to fetch weather data from a remote server. The app then processes this data and displays it to you in a user-friendly format. You are not directly interacting with the API, but the app is using it behind the scenes to provide you with the weather information.