Reference library

API design & gRPC

REST best practices, protobuf, API versioning, and backward-compatible service contracts.

3 matches
API design & gRPC easy

How to Add HATEOAS Links to a Python API Response

Build a Python API resource class that adds self and next HATEOAS links to JSON responses, with a mock example for pagination.

hateoas api-design rest
Python
import json


class Resource:
    def __init__(self, name, data, next_page=None):
        self.links = {"self": f"/api/resources/{name}"}
        if next_page is not None:
            self.links["next"] = f"/api/resources?page={next_page}"
        self.data = data

    def to_dict(self):
        return {"links": self.…
13 0 Open
API design & gRPC easy

How to Build a Simple Filter Helper in Python for API Design

Create a reusable data filter service with dataclasses that mimics gRPC request/response patterns for filtering dataset records.

filtering dataclasses grpc
Python
from dataclasses import dataclass, field
from typing import List, Optional, Dict, Any


@dataclass
class FilterRequest:
    """A simple filter request mirroring a gRPC message structure."""
    field_name: str
    operator: str  # eq, ne, gt, lt, contains
    value: Any
    page_size: int = 10
    page_token: Optional…
13 0 Open
API design & gRPC easy

How to Implement Pagination with Offset and Limit in Python

A mock API pagination pattern that parses page and per_page query parameters, computes offset and limit, and slices a list of items for a specific page.

api pagination query-params
Python
def paginate(items, page, per_page):
    offset = (page - 1) * per_page
    return items[offset:offset + per_page]


def parse_query_params(query_string):
    params = {}
    if query_string:
        for pair in query_string.split("&"):
            key, value = pair.split("=")
            params[key] = value
    page …
12 0 Open

Browse by section

Each section groups closely related Python snippets.

API design & gRPC — Python code examples

What you will find here

This page collects api design & grpc snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.

Samples vs tutorials and challenges

Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.