Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    NODENode.js

    Runtime and core tooling

    • What is Node.js?
    • CommonJS and ES modules
    • npm and package.json
    • process and command-line apps

    Async I/O and events

    • Event loop: callbacks to async/await
    • Files and paths with fs/promises
    • EventEmitter
    • Streams and backpressure

    HTTP and APIs

    • Your first HTTP server
    • Routing and JSON bodies
    • Build a tiny router and middleware chain
    • REST: resources and status codes
    • Validation and error handling

    Production: security, testing and deployment

    • Authentication basics with crypto
    • Configuration and environment secrets
    • Testing with assert and node:test
    • API security fundamentals
    • Project: tasks REST API and deployment
    Node.js

    HTTP and APIs · Lesson 12 of 18

    REST: resources and status codes

    Design noun-based URLs and use verbs and status codes as stable contracts.

    11 minutes2 games

    A REST API exposes resources such as /tasks and /tasks/42, not actions like /getTasks. The HTTP method carries the action: GET reads, POST creates, PUT replaces, PATCH partially updates and DELETE removes. The contract includes schema, status and errors.

    GET /tasks

    POST /tasks

    PATCH /tasks/:id

    DELETE /tasks/:id

    Node.js
    function result(method, exists) {
      if (method === "POST") return { status: 201, body: "created" }
      if (!exists) return { status: 404, body: "not found" }
      if (method === "DELETE") return { status: 204, body: "" }
      return { status: 200, body: "ok" }
    }
    console.log(result("POST", false).status, result("GET", false).status, result("DELETE", true).status)

    Common statuses: 200 success, 201 created with Location, 204 success without a body, 400 malformed request, 401 unauthenticated, 403 known but forbidden, 404 absent, 409 conflict, 422 validation failure, and 500 unexpected server failure.

    Important

    GET, PUT and DELETE should be idempotent: repeating the same request has the same final effect. POST usually is not; payments and sensitive operations need idempotency keys so network retries do not duplicate them.

    Quick question

    A resource was created successfully. Best status?

    Interview question

    How do 401 and 403 differ?

    Exercise

    Write statusFor(action, found) returning 201 for create, 404 when absent, 204 for delete, otherwise 200. Print 201 404 204 200.

    Expected output: 201 404 204 200

    Node.js
    function statusFor(action, found) {
    
    }
    console.log(statusFor("create", false), statusFor("read", false), statusFor("delete", true), statusFor("read", true))

    Learn more from

    • MDN: HTTP methodsdeveloper.mozilla.org
    • Microsoft: REST API guidelinesgithub.com

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousBuild a tiny router and middleware chainNextValidation and error handling
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.