0
0
Rest-apiConceptBeginner · 3 min read

What is REST API: Simple Explanation and Example

A REST API is a way for different software systems to talk to each other over the internet using simple rules. It uses standard web methods like GET and POST to request or send data, making it easy to connect apps and services.
⚙️

How It Works

Imagine you want to order a pizza by calling a restaurant. You tell them what you want, and they send it to your home. A REST API works similarly but for software. One program (the client) sends a request to another program (the server) asking for information or to do something.

The communication happens over the internet using simple commands called HTTP methods like GET to get data, POST to send data, PUT to update data, and DELETE to remove data. The server then responds with the requested information or confirmation.

This system is easy to understand and use because it follows clear rules and uses standard web technology, making it popular for building web and mobile apps.

💻

Example

This example shows a simple REST API server in Python using Flask. It responds to a GET request by sending a list of fruits.

python
from flask import Flask, jsonify

app = Flask(__name__)

fruits = ['apple', 'banana', 'cherry']

@app.route('/fruits', methods=['GET'])
def get_fruits():
    return jsonify(fruits)

if __name__ == '__main__':
    app.run(debug=True)
Output
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) When you visit http://127.0.0.1:5000/fruits in a browser or API tool, you get: ["apple", "banana", "cherry"]
🎯

When to Use

Use a REST API when you want different programs or devices to share data or services over the internet easily. For example:

  • Mobile apps getting data from a web server
  • Websites showing live information like weather or news
  • Connecting different parts of a system, like a payment service and an online store

REST APIs are great because they are simple, use standard web tools, and work well across many platforms.

Key Points

  • REST stands for Representational State Transfer, a style for building APIs.
  • It uses standard HTTP methods like GET, POST, PUT, DELETE.
  • Data is usually sent in formats like JSON, which is easy to read and write.
  • REST APIs make it simple for different software to communicate over the web.

Key Takeaways

A REST API lets software communicate over the internet using simple web commands.
It uses HTTP methods like GET and POST to request or send data.
REST APIs are widely used for connecting web and mobile apps to servers.
They are easy to understand because they follow clear, standard rules.
Data is often exchanged in JSON format for simplicity and readability.