liveBook · Manning

Api call

As explained in Learn Go with Pocket-Sized Projects

An HTTP request is a message sent by an HTTP client to ask a server to perform an operation or provide a resource.

An API call is a client request to a server, identified by an endpoint path and method, that asks for a resource or operation. HTTP calls can carry JSON or form data in the request body, while gRPC calls use defined request and response messages. section 8.2.3 section 10.1.1

A practical API call typically specifies:

  • An HTTP method and route, such as PUT /games/{game_id}, describing the operation and target resource. section 8.2.3
  • Input data, such as a JSON object containing a guess, or form values parsed from an HTTP request. section 8.2.3 section 11.4.2
  • A handler that extracts parameters, decodes input, calls backend logic, and returns a response or redirect. section 11.3.1 section 11.4.2
  • A stable request and response shape, especially for gRPC, so later fields can be added without breaking existing clients. section 10.1.1

Submitting a guess

A client can send PUT /games/123456 with {"guess":"hello"}. The handler decodes the body into a GuessRequest, rejects malformed input with HTTP 400, and processes the game identified by the path.

Listing 10.6 service.proto: Request and response
import "habit.proto"; #1

service Habits { 
    ... 
}

// CreateHabitRequest is the message sent to create a habit.
message CreateHabitRequest {
    // Name of the new habit. Cannot be empty.
    string name = 1;
    // Frequency of the new habit. Will default to once per week.
    optional int32 weekly_frequency = 2; #2
}

// CreateHabitResponse is the response of the create endpoint.
message CreateHabitResponse {
    Habit habit = 1;
}

Inspect a version-compatible gRPC request and response definition for creating a habit. section 10.1.1

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Explains paths, methods, bodies, parameter parsing, validation, redirects, and version-compatible request structures without detailing transport internals.
Examples
Demonstrates game guesses, habit creation, habit ticking, curl commands, Go requests, JSON bodies, and form submissions.
What it assumes
Assumes basic Go and HTTP knowledge while recapping server creation and teaching endpoint-specific request parsing.
What you can do after
Build it from scratch with Go handlers, decoded inputs, registered routes, backend calls, redirects, and request tests.
How it connects
Connects HTTP requests with REST, JSON, routing, URL parameters, form values, gRPC, Protobuf, and request/response design.

Also explained in

Compare how 3 books explain api call →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.