Demystifying APIs
Published: 2023-03-17 06:59:31

<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674574945116/d830d440-378d-4236-93ca-dbdb1460c7b8.webp" alt class="image--center mx-auto" /></p>
<h2 id="heading-what-is-an-api">What is an API?</h2>
<p>APIs (Application Programming Interfaces) are a way for different software systems to communicate with each other. They allow the frontend (i.e. the part of the application that interacts with the user) to send requests to the backend (i.e. the part of the application that interacts with the database or other external services) and receive responses.</p>
<ul>
<li><p>APIs are like the middlemen of the internet. They're the go-betweens that help different websites and apps talk to each other, kind of like that one friend you have who's really good at setting people up on dates.</p>
</li>
<li><p>Just like your matchmaking friend, APIs make sure that the right information gets sent to the right place, so everyone's happy and nobody gets ghosted.</p>
</li>
</ul>
<ul>
<li><p>APIs are like the oxygen of the internet. They're everywhere and you don't even realize it. They're the secret sauce that makes all your favorite apps and websites work together seamlessly.</p>
</li>
<li><p>APIs are a fundamental building block of the modern internet, and their presence can be found everywhere from web development to mobile apps, to cloud computing and beyond.</p>
</li>
<li><p>Their widespread use and integration allow for seamless communication and data exchange, and their importance in driving innovation in the software industry cannot be overstated.</p>
</li>
</ul>
<h2 id="heading-types-of-api">Types of API</h2>
<ol>
<li><p><strong>Public API</strong> - Also known as Open API available to developers and other users with minimal restrictions.</p>
</li>
<li><p><strong>Partner API</strong> - A partner API, only available to specifically selected and authorized outside developers or API consumers, is a means to facilitate business-to-business activities.</p>
</li>
<li><p><strong>Internal API -</strong> An internal or private API is only meant to be used inside the company to link together systems and data. For instance, an internal API may link the payroll and HR systems of a firm.</p>
</li>
<li><p><strong>Composite API</strong> - A composite API majority of the time, integrates two or more APIs to create a chain of connected or interdependent activities.</p>
</li>
</ol>
<h2 id="heading-types-of-api-protocols">Types of API Protocols</h2>
<ol>
<li><p><strong>SOAP</strong> - <strong>Simple Objects Access Protocol</strong></p>
</li>
<li><p><strong>REST</strong> - <strong>Representational State Transfer</strong></p>
</li>
<li><p><strong>JSON-RPC - JavaScript Object Notation- Remote Procedural Call</strong></p>
</li>
<li><p><strong>gRPC - Google Remote Procedural Call</strong></p>
</li>
<li><p><strong>GraphQL - Graph QL</strong></p>
</li>
<li><p><strong>XML-RPC - Extensible Markup Language Remote Procedural Call</strong></p>
</li>
<li><p><strong>Apache Thrift -</strong> Implementation of RPC framework</p>
</li>
</ol>
<p>We will be focussing on Rest and Soap Protocol in this blog.</p>
<h2 id="heading-what-is-rest-and-soap-protocol">What is Rest and Soap Protocol</h2>
<ol>
<li><p><strong>Soap Protocol</strong></p>
<p> <img src="https://slideplayer.com/slide/17908091/108/images/5/SOAP-based+middleware.jpg" alt="Chapter 4 SOAP: Simple Object Access Protocol - ppt download" /></p>
<ol>
<li><p><strong>S</strong>OAP (Simple Object Access Protocol) is an XML-based protocol for sending and receiving messages over the internet. It is typically used for building web services and is often used as an alternative to REST.</p>
</li>
<li><p>SOAP messages are typically sent over HTTP, but can also be sent over other transport protocols such as SMTP (Simple Mail Transfer Protocol). A SOAP message consists of an Envelope element, which contains a header and a body. The header contains metadata, such as authentication information, while the body contains the actual data being sent.</p>
</li>
<li><p>Messages in SOAP are encoded in XML specifically and have a properly defined format:</p>
<ul>
<li><p><em>Envelope</em>: Literally envelopes the entire message/data in tags.</p>
</li>
<li><p><em>Header</em>: Defines all extra information that might be needed to process this data. This is an optional element.</p>
</li>
<li><p><em>Body</em>: This is where we actually write the request for data required/ where all the requested data is added.</p>
</li>
<li><p><em>Fault</em>: Defines all the errors that may arise in the data during/due to transmission and measures to handle them.</p>
</li>
</ul>
</li>
</ol>
</li>
<li><p><strong>REST Protocol</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674577634462/d825842a-b671-4125-9c57-96b1ec9b8eac.jpeg" alt class="image--center mx-auto" /></p>
<ol>
<li><p>REST protocols overcome SOAP's dependency on XML by including JSON (the most popular), HTML, Python, plain text, and media files, REST protocols get around SOAP's reliance on XML. However, REST eliminates SOAP's extensibility to other protocols by only using HTTP/HTTPS for data delivery. RESTful APIs are APIs that use the REST protocol.</p>
</li>
<li><p>Client-server architecture and statelessness are requirements for REST APIs. It is implied by stateless communication that no client data is kept in memory in between GET queries. All of these GET queries to need to be separate and unconnected. Every action in REST is given a distinct URL, allowing the server to know exactly what to do in response to a request by knowing which instructions to carry out. Caching is supported via REST. Thus, in order to increase speed and efficiency, the browser can locally store the results of the request and periodically retrieve them as needed.</p>
</li>
<li><p>A typical REST request has the following components:</p>
<ul>
<li><p><em>Endpoint</em>: The destination URL from which data is being requested.</p>
</li>
<li><p><em>Method</em>: We use predefined methods such as GET, POST, PUT or DELETE to fetch the data. These methods vary from one another. Ex. when using GET, the data is appended to the end of the URL string, whereas in POST, the data is sent along with the HTTP request.</p>
</li>
<li><p><em>Headers</em>: They define the request's details and dictate the proper format in which the response must be received.</p>
</li>
<li><p><em>Body</em>: The actual data sent by the service.</p>
</li>
</ul>
</li>
</ol>
</li>
</ol>
<h1 id="heading-what-are-the-main-types-of-http-vulnerability"><strong>What are the main types of HTTP vulnerability?</strong></h1>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674577873115/3c1a864d-baa1-4a4d-b5b5-a0068c6319a3.jpeg" alt class="image--center mx-auto" /></p>
<ul>
<li><p><strong>Cross-site scripting</strong> - Commonly known XSS is when an attacker injects HTML markup or JavaScript into the affected web application's front-end client.</p>
</li>
<li><p><strong>SQL injection -</strong> SQL injection is <strong>a code injection technique that might destroy your database</strong>.</p>
</li>
<li><p><strong>DDOS attacks -</strong> A distributed denial-of-service (<strong><em>DDoS</em></strong>) <strong><em>attack</em></strong> is a malicious attempt to disrupt the normal traffic of a targeted server, service or network by overwhelming traffic</p>
</li>
<li><p><strong>Cross-site request forgery -</strong> Cross-Site Request Forgery (CSRF) is an attack that forces an end user to execute unwanted actions on a web application in which they’re currently authenticated</p>
</li>
</ul>
<h2 id="heading-how-to-secure-an-api">How to secure an API?</h2>
<ul>
<li><p>The first method of security is to use HTTPS on your site</p>
</li>
<li><p>The second method of security is to use Password hash you can apply some logic to hash the password</p>
</li>
<li><p>The third method of security is to add a password over every endpoint so that no one can access it</p>
</li>
<li><p>The fourth method of security is to add timestamps in API authentication adding timestamps to APIs can help you secure the API.</p>
</li>
</ul>
<h3 id="heading-if-you-have-reached-this-point-and-have-honestly-read-every-part-of-this-blog">If you have reached this point and have honestly read every part of this blog.</h3>
<p><img src="https://media.makeameme.org/created/you-sirs-deserve.jpg" alt="You Sir's deserve My full respect - Angry Obama | Make a Meme" /></p>
<p>Give Yourself a Pat on back and keep Learning about API.</p>
<p>Stay tuned for more such amazing blogs🚀🙌<a target="_blank" href="https://medium.com/tag/api?source=post_page-----e8b61196778f---------------api-----------------">  
</a></p>
</br><p style="color:#757CF9;">This article is published w/ <a target="_blank" href="https://scattr.io?ref=dev">Scattr  ↗️</a></p>