惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
About on SuperTechFans
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 司徒正美
宝玉的分享
宝玉的分享
美团技术团队
量子位
The Cloudflare Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
IT之家
IT之家
爱范儿
爱范儿
J
Java Code Geeks
博客园 - Franky
Last Week in AI
Last Week in AI
B
Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
GbyAI
GbyAI
Recent Announcements
Recent Announcements
小众软件
小众软件
H
Help Net Security
Microsoft Azure Blog
Microsoft Azure Blog
MyScale Blog
MyScale Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
What Is REST API ?
Mohamed Elmorsy · 2026-06-03 · via DEV Community
Cover image for What Is REST API ?

Mohamed Elmorsy

A REST API (Representational State Transfer API) enables communication between a client and a server over HTTP. It exchanges data — typically in JSON format — using standard web protocols, making it one of the most widely adopted architectural styles for building web services today.

If you're wondering what is HTTP method or what is HTTP at all, you can check my previous article What Is HTTP & HTTPS ?.

Key characteristics of a REST API:

  • Uses standard HTTP methods: GET, POST, PUT, and DELETE
  • The client sends requests to server endpoints (URLs)
  • The server responds with the requested data in formats like JSON, XML, HTML, or binary (e.g., images)

Note: REST is an architectural style that defines how APIs should be designed, whereas HTTP is the protocol used to transfer data. They work together, but they are not the same thing.


Common HTTP Methods

1. GET

GET is used to retrieve data from the server without modifying anything. It is idempotent — calling it multiple times produces the same result.

Common response codes:

Status Code Meaning
200 OK Data found and returned successfully
404 Not Found The requested resource does not exist
400 Bad Request The request was malformed

Example request:

GET /users/123

This request fetches the data for the user with ID 123.

Go implementation:

package main

import (
    "fmt"
    "net/http"
)

func main() {
    client := &http.Client{}
    url := "https://api.example.com/users/123"

    req, err := http.NewRequest(http.MethodGet, url, nil)
    if err != nil {
        panic(err)
    }
    req.Header.Set("Content-Type", "application/json")

    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    fmt.Printf("Response Status: %s\n", resp.Status)
}


2. POST

POST is used to create a new resource on the server. On success, it returns 201 Created, often with a Location header pointing to the newly created resource.

Example request:

POST /users
Content-Type: application/json

{
  "name": "Anne",
  "email": "anne@example.com"
}

This request creates a new user with the provided data.

Go implementation:

package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
)

type User struct {
    Name  string `json:"name"`
    Email string `json:"email"`
}

func main() {
    url := "https://api.example.com/users"

    user := User{
        Name:  "Anne",
        Email: "anne@example.com",
    }

    jsonData, err := json.Marshal(user)
    if err != nil {
        panic(err)
    }

    resp, err := http.Post(url, "application/json", bytes.NewBuffer(jsonData))
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    fmt.Printf("Response Status: %s\n", resp.Status)
}


3. PUT

PUT is used to update an existing resource or create it if it does not exist. Unlike PATCH, it requires the complete resource to be sent in the request body — it replaces the resource entirely.

Example request:

PUT /users/123
Content-Type: application/json

{
  "name": "Anne",
  "email": "anne@example.com"
}

This request updates the user with ID 123, or creates a new one if that user does not exist.

Go implementation:

package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
)

type User struct {
    Name  string `json:"name"`
    Email string `json:"email"`
}

func main() {
    client := &http.Client{}
    url := "https://api.example.com/users/123"

    user := User{
        Name:  "Anne",
        Email: "anne@example.com",
    }

    jsonData, err := json.Marshal(user)
    if err != nil {
        panic(err)
    }

    req, err := http.NewRequest(http.MethodPut, url, bytes.NewBuffer(jsonData))
    if err != nil {
        panic(err)
    }
    req.Header.Set("Content-Type", "application/json")

    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    fmt.Printf("Response Status: %s\n", resp.Status)
}


4. DELETE

DELETE is used to remove a resource identified by its URI. On successful deletion, the server returns 200 OK (with a response body) or 204 No Content (with no body).

Example request:

DELETE /users/123

This request deletes the user with ID 123.

Go implementation:

package main

import (
    "fmt"
    "net/http"
)

func main() {
    client := &http.Client{}
    url := "https://api.example.com/users/123"

    req, err := http.NewRequest(http.MethodDelete, url, nil)
    if err != nil {
        panic(err)
    }
    req.Header.Set("Content-Type", "application/json")

    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    fmt.Printf("Response Status: %s\n", resp.Status)
}


Summary

Method Purpose Success Code
GET Retrieve a resource 200 OK
POST Create a new resource 201 Created
PUT Update or replace a resource 200 OK
DELETE Remove a resource 200 OK / 204 No Content

Understanding these four methods covers the majority of real-world REST API interactions. In a future article, we'll dive into PATCH (partial updates), authentication with API keys and JWT, and how to handle errors properly on both the client and server sides


REST is powerful, but what if the server could give you exactly what you ask for — nothing more, nothing less? That's the promise of GraphQL. Next up, we break it down.