Is REST API a code?

May 7, 2024 ยท 2 min read

REST (Representational State Transfer) API is an architectural style for building web services, not a coding framework or library. However, there is often confusion around whether REST APIs themselves constitute code.

At its core, a REST API is a set of principles and constraints for creating web services. Adhering to these principles enables some nice benefits like loose coupling, scalability, and flexibility. But REST itself does not provide any ready-made code or functionality.

What Exactly is a REST API?

A REST API allows client applications to access and manipulate resources hosted on a server. Resources are represented as URLs, and clients use standard HTTP methods like GET, POST, PUT, and DELETE to perform operations.

Here is an example GET request to a REST API:

GET /api/users/1234

This would retrieve the user resource with ID 1234.

The key principles of REST include:

  • Resources are identified by URIs (e.g. /api/users)
  • Uniform interface (HTTP verbs like GET and POST)
  • Stateless interactions
  • Self-descriptive messages (JSON, XML)
  • Following these constraints and architectural style results in a REST API. But there is no code automatically generated - you still need to write the application logic, routes, controllers, models etc.

    Building a REST API Requires Coding

    While REST provides guiding principles, developers must write all the code required for an actual functioning API:

  • Route handlers for each URL
  • Controller logic for each route
  • Database models and schema
  • Serialization and deserialization of data
  • User authentication and authorization
  • Here is an example of some Python code for a simple REST API:

    @app.route("/api/users", methods=["GET"]) 
    def get_users():
        users = db.query(User) 
        return jsonify(users)

    So while REST is an architectural style and design concept, implementing a REST API in any programming language still requires writing potentially thousands of lines of code for the application logic, routes, controllers, persistence layer etc.

    Key Takeaways

  • REST is an architectural approach and set of constraints, not a code library
  • Building an actual REST API requires writing code for routing, controllers, models etc.
  • Following REST principles enables loose coupling and scalability benefits
  • Coding a REST API from scratch can mean writing thousands of lines of code
  • So in summary, REST API is not itself code, but implementing one still involves plenty of coding!

    Browse by tags:

    Browse by language:

    The easiest way to do Web Scraping

    Get HTML from any page with a simple API call. We handle proxy rotation, browser identities, automatic retries, CAPTCHAs, JavaScript rendering, etc automatically for you


    Try ProxiesAPI for free

    curl "http://api.proxiesapi.com/?key=API_KEY&url=https://example.com"

    <!doctype html>
    <html>
    <head>
        <title>Example Domain</title>
        <meta charset="utf-8" />
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
    ...

    X

    Don't leave just yet!

    Enter your email below to claim your free API key: