JavaRush
AI Academy
new
Promotion
Learning
Courses
Tasks
Quizzes
Games
Help
Schedule of nudges
Internship
Community
Users
Forum
Chat
Articles
Activities
Reviews
Subscriptions
Light theme

Lectures

  • Reviews
  • About us
  • CS50
Start
Start learning
Start learning
  • My progress
  • Courses
  • Quest map
  • Lectures
  • Unit tests for HTTP handlers: httptest.NewRecorder and httptest.NewRequest

    Go SELF
    64 level,0 lecture
    We break down how to unit-test HTTP handlers in Go without starting a server: call ServeHTTP manually, create a request via httptest.NewRequest, and capture the response with httptest.NewRecorder. We learn to verify the status, the Content-Type header, the JSON contract via decoding, the error envelope for validation/ not_found/ internal, and we also write helpers with t.Helper() and table-driven tests.
    Open
  • Integration HTTP Tests: httptest.Server

    Go SELF
    64 level,1 lecture
    Let’s break down how to write integration tests for the HTTP layer in Go using httptest.NewServer: we spin up a test server with your http.Handler (mux + middleware + handlers), make requests “like a client” via ts.Client() and ts.URL, consistently close defer ts. Close() and resp. Body. Close(), and then verify the contract: status, Content-Type, and JSON structure (success DTO and error envelope), including 400/ 404/ 500 scenarios.
    Open
  • Dependency test doubles for API tests

    Go SELF
    64 level,2 lecture
    We break down how to test the HTTP contract of handlers in Go without a real database and infrastructure: extract dependencies into minimal interfaces (for example, TaskService), replace them with test doubles ( stub/ fake/ mock), verify mapping of domain errors via errors.Is/ errors.As to statuses ( 404/ 400/ 500), and simplify tests with helpers like t.Helper() and JSON decoding.
    Open
  • Separation of responsibility: core logic separate from the HTTP layer

    Go SELF
    64 level,3 lecture
    We break down how to build a “thin” HTTP layer in Go and move business rules into core: domain models without JSON tags, a usecase service with no dependency on net/http, typed domain errors ( ValidationError, NotFoundError), and mapping errors to statuses/API contracts at the handler level. Separately, we show how this simplifies testing: core is tested with regular unit tests without httptest, and HTTP is verified against the contract.
    Open
  • API documentation — curl examples, errors, auth header

    Go SELF
    64 level,4 lecture
    We break down how to structure JSON API documentation as a contract: what must go into the “header” (base URL, prefix, format), how to write reproducible examples using curl, how to pin authorization to a single header X-API-Key, and how to standardize errors with a single JSON error envelope with statuses 400/ 401/ 403/ 404/ 500. We also show useful nuances like X-Request-ID and common mistakes that turn a README into fan fiction.
    Open
Learn
  • Registration
  • Java course
  • Help with tasks
  • Pricing
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Activities
Company
  • About us
  • Contacts
  • Reviews
  • FAQ
  • Support
JavaRushJavaRush — is an interactive online course for learning Java programming from scratch. It contains 1200 practical tasks with one-click solution checking, the necessary minimum of theory on Java basics, and motivating features that help you complete the course: games, quizzes, interesting projects and articles on effective learning and the career of a Java developer.
Follow us
Язык интерфейса
Русский
English
Українська
"Programmers are not born" © 2026 JavaRush
MastercardVisa
"Programmers are not born" © 2026 JavaRush