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:
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:
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
So in summary, REST API is not itself code, but implementing one still involves plenty of coding!