<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Asini Karunanayaka on Medium]]></title>
        <description><![CDATA[Stories by Asini Karunanayaka on Medium]]></description>
        <link>https://medium.com/@asini.karunanayaka13500?source=rss-c1616bcc942d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*103U5G1bdsV404Wt10Shsg.jpeg</url>
            <title>Stories by Asini Karunanayaka on Medium</title>
            <link>https://medium.com/@asini.karunanayaka13500?source=rss-c1616bcc942d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 11:39:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@asini.karunanayaka13500/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[REST API vs. GraphQL: Understanding the Difference.]]></title>
            <link>https://medium.com/@asini.karunanayaka13500/rest-api-vs-graphql-understanding-the-difference-1ec7c457523b?source=rss-c1616bcc942d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ec7c457523b</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[graphql-vs-rest]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Asini Karunanayaka]]></dc:creator>
            <pubDate>Mon, 30 Nov 2026 08:47:39 GMT</pubDate>
            <atom:updated>2026-11-30T08:47:39.175Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*YRvYLCRpKMLmYmCThqrmvA.png" /></figure><h3>Introduction</h3><p>APIs let different apps talk to eachother and swap data. REST and GraphQL are two ways to build them. REST works with endpoints tied to resources. Uses HTTP methods. GraphQL, on the hand, lets the client ask for exactly the data it needs through queries. When you know how these two differ, it is easier to pick the one for your app.</p><h3>What Is a REST API?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*_z_lunOkozA6kcNKa9AvYQ.png" /></figure><p>REST, which stands for Representational State Transfer, was introduced by Roy Fielding in the year 2000. REST offers guidelines for building web services that are both scalable and easy to maintain.</p><p>REST APIs arrange application data into resources, for example employees, products or orders. Each resource is identified by a URL known as an endpoint. Clients talk to these endpoints by using HTTP methods.</p><p>For example, an employee management system might use the endpoints:</p><p>GET - Retrieve all employees --&gt; /api/employees <br>GET - Retrieve an employee --&gt; /api/employees/10 <br>POST - Create an employee --&gt; /api/employees <br>PUT - Replace employee information--&gt; /api/employees/10 <br>PATCH - Update specific information--&gt;/api/employees/10 <br>DELETE - Delete an employee--&gt; /api/employees/10</p><p>REST is built on a key design ideas. These include keeping the client and server making each request stand alone, allowing responses to be cached, using one consistent way to interact and organizing things in layers.</p><p>These ideas help make APIs that behave in expected ways, grow and are simpler to look after.</p><h3>What Is GraphQL?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*OElIss2Y51-y_p6jqO_lMQ.png" /></figure><p>GraphQL is a query language for APIs and a server-side runtime that runs queries. GraphQL was created by Facebook ( Meta) in 2012 and made public in 2015.</p><p>In contrast to REST, where endpoints usually decide what data is returned, GraphQL lets clients choose the fields they want. GraphQL often uses one endpoint to serve many different data requests.</p><p>Suppose you have an app that needs an employees details and the projects they are assigned to.</p><p>With REST, the front end might have to send two requests:</p><pre>GET /api/employees/10<br>GET /api/employees/10/projects</pre><p>With GraphQL, both can be retrieved using one query:</p><pre>query {<br>  employee(id: &quot;10&quot;) {<br>    name<br>    position<br>    projects {<br>      projectName<br>      status<br>    }<br>  }<br>}</pre><p>The server returns the requested data in the same structure:</p><pre>{<br>  &quot;data&quot;: {<br>    &quot;employee&quot;: {<br>      &quot;name&quot;: &quot;ABC&quot;,<br>      &quot;position&quot;: &quot;Software Engineer&quot;,<br>      &quot;projects&quot;: [<br>        {<br>          &quot;projectName&quot;: &quot;Employee Management System&quot;,<br>          &quot;status&quot;: &quot;In Progress&quot;<br>        }<br>      ]<br>    }<br>  }<br>}</pre><p>This allows clients to retrieve related information without making multiple requests or receiving unnecessary fields.</p><h3>Core GraphQL Concepts</h3><p>Understanding five concepts helps explain how GraphQL works.</p><p><strong>1. Schema</strong> - A schema defines the available data types, fields, and operations.</p><pre>type Employee {<br>  id: ID!<br>  name: String!<br>  position: String!<br>}</pre><p>Here, Employee defines an employee&#39;s structure, while ID and String represent the field types. The ! indicates that a field cannot be null.</p><p><strong>2. Queries</strong> - Queries retrieve data from the server, similar to GET requests in REST.</p><pre>query {<br>  employee(id: &quot;10&quot;) {<br>    name<br>    position<br>  }<br>}</pre><p>This requests only the employee’s name and position.</p><p><strong>3. Mutations</strong> - Mutations create, update, or delete data.</p><pre>mutation {<br>  addEmployee(<br>    name: &quot;ABC&quot;,<br>    position: &quot;Software Engineer&quot;<br>  ) {<br>    id<br>    name<br>  }<br>}</pre><p>This creates an employee and returns the newly created employee’s ID and name.</p><p><strong>4. Subscriptions - </strong>Subscriptions allow clients to receive updates when specific events occur on the server. They are commonly used for real-time features such as chat applications, notifications, and live dashboards.</p><pre>subscription {<br>  messageReceived {<br>    id<br>    sender<br>    message<br>  }<br>}</pre><p>Subscriptions commonly use WebSockets or another supported real-time transport mechanism.</p><p><strong>5. Resolvers - </strong>Resolvers are functions that determine how GraphQL retrieves or modifies requested data.</p><pre>const resolvers = {<br>  Query: {<br>    employee: (_, { id }) =&gt;<br>      employees.find(<br>        employee =&gt; employee.id === Number(id)<br>      )<br>  }<br>};</pre><p>This resolver searches the employee collection using the requested ID and returns the matching employee.</p><p>In simple terms, the schema defines available data, queries retrieve it, mutations modify it, subscriptions provide updates, and resolvers handle the underlying operations.</p><h3>REST API vs. GraphQL : Main Differences</h3><p>- <strong>Architecture</strong></p><ul><li>REST: Architectural style.</li><li>GraphQL: Query language.</li></ul><p>- <strong>Endpoints</strong></p><ul><li>REST: Multiple endpoints.</li><li>GraphQL: Typically one endpoint.</li></ul><p>- <strong>Data Fetching</strong></p><ul><li>REST: Server defines response data.</li><li>GraphQL: Client selects required fields.</li></ul><p>- <strong>HTTP Methods</strong></p><ul><li>REST: Uses GET, POST, PUT, PATCH, DELETE.</li><li>GraphQL: Commonly uses POST.</li></ul><p>- <strong>Overfetching</strong></p><ul><li>REST: Can return unnecessary data.</li><li>GraphQL: Fetches requested fields.</li></ul><p>- <strong>Underfetching</strong></p><ul><li>REST: May require multiple requests.</li><li>GraphQL: Can retrieve related data together.</li></ul><p>- <strong>Caching</strong></p><ul><li>REST: Supports standard HTTP caching.</li><li>GraphQL: Requires additional strategies.</li></ul><p>- <strong>Versioning</strong></p><ul><li>REST: Commonly uses API versions.</li><li>GraphQL: Supports schema evolution.</li></ul><p>- <strong>Learning Curve</strong></p><ul><li>REST: Easier to learn.</li><li>GraphQL: Requires understanding additional concepts.</li></ul><h3>Advantages and Disadvantages</h3><p>Both REST and GraphQL offer different benefits depending on the application’s requirements.</p><h3>REST API</h3><p><strong>Advantages:</strong></p><ul><li>Simple and easy to understand.</li><li>Strong support for standard HTTP caching.</li><li>Established tools, libraries, and ecosystem.</li><li>Suitable for CRUD applications.</li></ul><p><strong>Disadvantages:</strong></p><ul><li>Can cause overfetching and underfetching.</li><li>Less flexible response structures.</li><li>Significant changes may require API versioning.</li><li>Related data may require multiple requests.</li></ul><h3>GraphQL</h3><p><strong>Advantages:</strong></p><ul><li>Flexible data fetching.</li><li>Reduces unnecessary network requests.</li><li>Strongly typed schema.</li><li>Allows different clients to request different fields.</li></ul><p><strong>Disadvantages:</strong></p><ul><li>More complex implementation.</li><li>Caching requires additional strategies.</li><li>Poorly designed resolvers can cause N+1 query problems.</li><li>Complex queries can affect server performance.</li></ul><h3>Performance and Security Considerations</h3><p>GraphQL is not automatically faster than REST. The real speed depends on database queries, network latency, caching and server-side processing.</p><p>One common GraphQL performance issue is the N+1 query problem. Take retrieving 100 employees and their departments. That could mean one query for employees and another query for each employees department.</p><p>Developers can ease this problem with tools like DataLoader. DataLoader. Caches data-loading operations.</p><p>GraphQL also supports queries. So developers should set query depth limits, pagination and complexity restrictions to prevent requests.</p><p>Both REST and GraphQL need security practices, including:</p><ul><li><strong>Authentication:</strong> Verifying user identity, commonly using JWTs.</li><li><strong>Authorization:</strong> Controlling which resources and operations users can access.</li><li><strong>Input Validation:</strong> Checking user-provided data before processing it.</li><li><strong>Rate Limiting:</strong> Restricting excessive requests.</li><li><strong>Query Protection:</strong> Applying depth and complexity limits to GraphQL queries.</li></ul><p>Neither approach provides complete security automatically. These protections must be implemented on the backend.</p><h3>When Should You Choose REST or GraphQL?</h3><p>The right choice depends on the application’s requirements.</p><p><strong>Choose REST when:</strong></p><ul><li>Building simple CRUD applications.</li><li>Standard HTTP caching is important.</li><li>Application data fits naturally into resource-based endpoints.</li><li>You want a straightforward API architecture.</li></ul><p>Examples include employee management systems, inventory applications, and basic booking systems.</p><p><strong>Choose GraphQL when:</strong></p><ul><li>The application has complex relationships between data.</li><li>Different clients require different data fields.</li><li>Flexible data fetching is important.</li><li>Information needs to be combined from multiple backend services.</li></ul><p>Examples include social media platforms, e-commerce applications, and project management systems.</p><h3>Can REST and GraphQL Be Used Together?</h3><p>Yes. REST and GraphQL can both live in one app. Say an app already uses REST services for users, products and orders. A team can add a GraphQL layer on top. That layer talks to the services in place. It gives the frontend a flexible way to fetch data. So a company gets the parts of GraphQL without throwing out the REST setup it already has.</p><h3>Conclusion</h3><p>REST and GraphQL solve the basic problem: making applications talk to backend services. Yet, REST and GraphQL use ways to fetch data.</p><p>REST offers a resource‑based structure that relies on strong HTTP support. GraphQL gives data fetching that lets the client define the queries.</p><p>Neither REST nor GraphQL is always better. The best choice depends on how complex the application’s what performance is needed and what the developers require.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ec7c457523b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>