HTTP APIs and map resources
Martin exposes map data and the resources that map clients need through one HTTP server. Its routes provide native tiles and TileJSON, an OGC API view, MapLibre styles, sprites, glyph ranges, map images, catalog data, and optional administration actions. See server runtime, configuration and reload, source catalog and lifecycle, and style resources and rendering for the wider server model.
Request routing
The server builds one route tree from the enabled capabilities. A configured route_prefix places the main API routes under a public subpath, while /health remains available at the server root for probes. Route order is part of the contract because the general tile path can also match names such as ogc; specific OGC routes and redirect routes are registered first. crates/…/server.rs• L148-263
This diagram shows how an incoming request moves from the shared server boundary to the handler that owns its resource type.
flowchart TD
A[HTTP request] --> B[Path normalization and route prefix]
B --> C{Path family}
C -->|/ogc| D[OGC API handlers]
C -->|/{source}/{z}/{x}/{y}| E[Tile handler]
C -->|/{source}| F[TileJSON metadata handler]
C -->|/style or /ogc/styles| G[Style handlers]
C -->|/sprite or /sdf_sprite| H[Sprite handlers]
C -->|/font| I[Font handler]
C -->|/catalog, /health, /cache| J[Catalog or administration handlers]
D --> K[Shared source and grid state]
E --> K
F --> K
G --> L[Style resource state]
H --> M[Sprite resource state]
I --> N[Font resource state]
The handlers receive shared source state as request data. They wait for the needed source state when a request depends on loading or refresh, then map source errors to HTTP classes such as not found, bad request, unavailable, or internal error. GET and HEAD are supported for most read routes, and metadata or generated resource responses use entity tags and compression where useful. crates/…/server.rs• L53-75 crates/…/server.rs• L128-146 crates/…/server.rs• L346-384
References: crates/…/server.rs• L148-198 crates/…/server.rs• L200-263 crates/…/server.rs• L346-384
Tile API
The tile API is the native path for fetching tiles from one source or a composite of several source IDs. A request names the source set and XYZ coordinate; the server resolves the sources, chooses a response format from the Accept header, applies the configured source processing, and returns the encoded tile or an empty response. crates/…/content.rs• L54-119
Tile metadata uses the shorter /{source_ids} route. It returns TileJSON with a tile URL template that points back to Martin. For one source it preserves that source's metadata; for several sources it combines useful bounds, layer, zoom, name, description, and attribution information. crates/…/metadata.rs• L25-113 crates/…/metadata.rs• L116-210
The API keeps old client URL forms working through permanent redirects. File suffixes on tile paths and the /tiles/ prefix redirect to the canonical path without an extension or prefix. The route order puts these redirects before the broad tile handler. crates/…/content.rs• L228-277 crates/…/server.rs• L200-210
References: crates/…/content.rs• L64-119 crates/…/content.rs• L228-277 crates/…/metadata.rs• L25-113 crates/…/metadata.rs• L116-210
OGC API - Tiles
The OGC API presents the served tile sources through standard discovery and link-based metadata under /ogc. Its landing page links to conformance, collections, and tile matrix sets. Collections describe individual sources, tilesets describe the grid and data type, and tile requests use the OGC row and column order. crates/…/landing.rs• L10-62 crates/…/collections.rs• L16-34
The OGC endpoints use the same source manager and tile-serving path as the native API. This keeps tile content and source rules consistent while changing the resource description and coordinate naming to match OGC API - Tiles. Only sources with a supported OGC tile matrix definition appear as OGC collections. crates/…/collections.rs• L97-170 crates/…/tile.rs• L24-65
Tile matrix set resources describe the coordinate reference system, axis order, origin, scale, matrix size, and tile size for each served grid. The conformance resource declares the OGC API - Common, OGC API - Tiles, and Tile Matrix Set classes that this interface supports. crates/…/tile_matrix_sets.rs• L23-68 crates/…/conformance.rs• L6-18
The OGC landing page also links to the server's OpenAPI description at /ogc/api. The description is filtered to the capabilities that the current build and runtime serve, and it is available as JSON or as a browser-facing HTML page. crates/…/landing.rs• L24-83 crates/…/openapi.rs• L35-121
The OGC conformance response adds Styles classes when resource serving is built in. It adds Maps classes only when rendering is enabled for the request, so discovery stays aligned with actual server behavior. crates/…/conformance.rs• L20-69
References: crates/…/landing.rs• L24-108 crates/…/openapi.rs• L35-121 crates/…/collections.rs• L97-170 crates/…/tilesets.rs• L132-275 crates/…/tile.rs• L24-65 crates/…/tile_matrix_sets.rs• L127-204 crates/…/conformance.rs• L20-69
OGC maps
The OGC Maps routes turn a style, one raster collection, or a selected set of raster collections into a map image. They accept a view described by a bounding box, a center, or a scale and return PNG, JPEG, or GeoTIFF when the client accepts that format. The response identifies the rendered area in web mercator so the image has a clear spatial meaning. crates/…/map.rs• L102-123 crates/…/map.rs• L391-444 crates/…/map.rs• L487-517
Collection maps use a generated raster style. Dataset maps combine drawable collections in request order, or all drawable collections when no selection is given. A collection must use a web-mercator grid and an image tile format before it can appear as a map. crates/…/generated_style.rs• L5-41 crates/…/map.rs• L87-90 crates/…/map.rs• L603-688
The map tile routes expose the same rendered views as tiled resources. They use WebMercatorQuad, validate the tile bounds, and provide tileset metadata before serving image tiles. These routes and the map links appear only when rendering is available. crates/…/map_tiles.rs• L50-100 crates/…/map_tiles.rs• L115-215 crates/…/map_tiles.rs• L217-335
References: crates/…/map.rs• L70-90 crates/…/map.rs• L102-123 crates/…/map.rs• L391-444 crates/…/map.rs• L487-688 crates/…/map_tiles.rs• L50-100 crates/…/map_tiles.rs• L115-335 crates/…/generated_style.rs• L5-41
MapLibre resources
MapLibre clients need more than map tiles. Martin serves style documents, sprite sheets and indexes, and glyph ranges so a style can refer to a complete set of map resources from the same server. These resources are discovered from the configured resource state and can use aliases that combine several source files.
Styles
The style endpoint returns a MapLibre Style Specification document for a configured style ID. It is available at the native /style/{style_id} path and at the OGC /ogc/styles/{style_id} path. Before returning it, Martin expands relative resource URLs against the request host and the configured public path. This lets clients request the tiles, sprites, and glyphs named by the style through the same deployment path. crates/…/styles.rs• L21-95
The OGC styles list provides discovery for configured styles. Each entry links to its style document and adds map and map-tiles links when rendering is enabled. crates/…/styles.rs• L12-69 crates/…/styles.rs• L72-104
When server-side rendering is enabled, a style also becomes a map image service. Clients can request an XYZ image tile or a static image from a center and zoom or from a bounding box. A static POST can add a GeoJSON feature collection as a temporary overlay. The service returns PNG, JPEG, or WebP images and rejects invalid camera, size, ratio, or overlay input before rendering. crates/…/styles_rendering.rs• L31-61 crates/…/styles_rendering.rs• L199-267 crates/…/styles_static.rs• L218-313 crates/…/styles_static.rs• L355-405
Rendering is an optional server capability. The catalog and OGC discovery report whether it is enabled, and image requests return a forbidden response when the capability is not available. The canonical image suffix is .jpg; .jpeg requests redirect to it. crates/…/admin.rs• L38-64 crates/…/conformance.rs• L20-69 crates/…/styles_static.rs• L251-273 crates/…/styles_rendering.rs• L279-320
References: crates/…/styles.rs• L21-115 crates/…/styles.rs• L12-104 crates/…/styles_rendering.rs• L31-61 crates/…/styles_rendering.rs• L199-320 crates/…/styles_static.rs• L218-405 martin/…/styles.rs• L24-82
Sprites
Sprite endpoints return either a PNG sheet or its JSON index. They also provide signed-distance-field variants for clients that need scalable icon rendering. A request can name one source or a configured combination; the server resolves the names before it creates or reuses the result. crates/…/sprites.rs• L24-82 crates/…/sprites.rs• L175-224
Sprite aliases are named combinations of configured sprite sources. The same alias works in the image and index paths, so the two resources stay paired. Plural paths are compatibility redirects to the singular canonical paths. martin/…/sprites.rs• L12-47 martin/…/sprites.rs• L51-76
References: crates/…/sprites.rs• L24-173 crates/…/sprites.rs• L175-345 martin/…/sprites.rs• L12-76
Fonts
The font endpoint serves a glyph range for a named font stack. It negotiates a supported content encoding with the client and returns the range as a protobuf resource. A font stack can resolve to several discovered fonts in fallback order, which lets a style request one stable name while the server supplies the needed glyphs. crates/…/fonts.rs• L16-106 martin/…/fonts.rs• L11-37
Font paths use a canonical form without a file extension. Plural paths and paths with an extension redirect to that form so MapLibre resource URLs have one stable target. crates/…/fonts.rs• L154-216
References: crates/…/fonts.rs• L16-106 crates/…/fonts.rs• L108-152 crates/…/fonts.rs• L154-220 martin/…/fonts.rs• L40-74
Catalog and administration
The catalog is the server's compact discovery view. GET /catalog reports configured tile, sprite, font, and style sources plus server capability flags, while GET /health gives a no-cache readiness and liveness result after tile sources have loaded. The root response points users to the catalog when the Web UI is not available. crates/…/admin.rs• L15-36 crates/…/admin.rs• L68-99 crates/…/server.rs• L128-146
The optional cache administration endpoint accepts DELETE /cache/{source_id}. It verifies the source, then removes its cached tiles when tile caching is enabled. The route has no built-in authentication and must be protected by the deployment boundary before it is exposed to untrusted clients. crates/…/cache.rs• L6-32 martin/…/srv.rs• L222-237
References: crates/…/admin.rs• L15-119 crates/…/server.rs• L128-146 crates/…/cache.rs• L6-32 martin/…/srv.rs• L222-237
Public URL construction
Responses that contain links must describe the URL that clients can reach through a reverse proxy. Martin uses an explicit base_path first, then route_prefix, and then forwarded request prefixes where the response type allows it. TileJSON also preserves request query parameters and can add a source version parameter for cache-busting. martin/…/srv.rs• L88-100 crates/…/metadata.rs• L54-111
OGC links and style URLs use the same public prefix rules. This keeps links self-contained when Martin is mounted below a proxy path instead of at /. A mismatch between the proxy path and these settings can make a valid response point to an unreachable resource. crates/…/link.rs• L49-58 crates/…/server.rs• L77-97
References: martin/…/srv.rs• L88-100 martin/…/srv.rs• L176-186 crates/…/metadata.rs• L54-111 crates/…/link.rs• L49-58 crates/…/styles.rs• L62-77
Change checklist
When these files or sections are changed, remember to consider these:
- Keep OGC routes registered before the broad
/{source_ids}tile routes. Otherwise/ogccan resolve as a tile source. - Keep redirect routes before their canonical broad routes. This applies to tile suffixes,
/tiles, plural resource names, and .jpeg image names. - Keep TileJSON, OGC links, and style URL expansion aligned with
base_path,route_prefix, and reverse-proxy headers. - When changing a resource URL shape, update both the style resource references and the matching image, index, or glyph route.
- When changing tile format handling, preserve the native tile response rules and the OGC content type mapping.
- When changing a source or resource alias contract, check the catalog output and the cache key's resolved-source behavior.
- When changing OGC capability routes, update the landing links, conformance classes, and filtered OpenAPI paths together.
- When changing map eligibility or image formats, keep collection links, generated styles, map tilesets, and map tile responses aligned.
- Treat cache purge as a deployment access-control concern because the endpoint has no authentication of its own.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A request uses an unknown source, collection, style, sprite, or font | The resource is not found and the client cannot build the map | Resolve the ID through the matching source manager before serving content |
| OGC metadata names a tile matrix set that does not match the source grid | The collection or tile request returns an OGC not-found error | Validate the collection and tileset pair before forwarding the tile request |
| A style JSON document is malformed | The style endpoint returns a bad request instead of a usable style | Parse the style before returning it |
| A renderer request has invalid coordinates, size, ratio, or overlay data | The image request fails with a bad request | Validate request values before rendering |
| Rendering is disabled or unavailable on the build | Style image or OGC map requests return forbidden | Check the catalog and OGC capability before depending on rendered images |
| A map request uses an unsupported CRS, conflicting view parameters, or an area that is too large | The OGC map request returns a client error | Use one supported CRS and one valid view description within the image limit |
| A collection is not raster or is not on web mercator | Its OGC map link or map request is unavailable | Use collection maps only for drawable raster collections |
A map tile is outside WebMercatorQuad | The map tile request returns not found | Use the advertised tile matrix and row and column limits |
| Public path settings do not match the reverse proxy mount | TileJSON, OGC, or style links point to the wrong URL | Set base_path or route_prefix to the public mount path |
| An untrusted client reaches cache purge | A source cache can be cleared on demand | Put the endpoint behind a trusted proxy or keep it disabled |
Key files
| File | Why to read it |
|---|---|
| crates/…/server.rs | Defines the shared server boundary, route order, shared request state, and path prefix behavior. |
| crates/…/content.rs | Shows the native tile request contract and how requests become tile responses. |
| crates/…/metadata.rs | Shows how source metadata becomes TileJSON and tile URL templates. |
| crates/…/landing.rs | Shows the OGC entry point and its discovery links. |
| crates/…/openapi.rs | Shows capability-aware OpenAPI and HTML API discovery. |
| crates/…/collections.rs | Shows how tile sources become OGC collections. |
| crates/…/tilesets.rs | Shows how source grids become OGC tileset metadata. |
| crates/…/tile.rs | Shows how OGC tile coordinates reach the native tile service. |
| crates/…/map.rs | Shows OGC map views for styles, collections, and datasets. |
| crates/…/map_tiles.rs | Shows OGC map tilesets and rendered map tile requests. |
| crates/…/styles.rs | Shows OGC style discovery and links to style resources. |
| crates/…/generated_style.rs | Shows how drawable raster collections become a map style. |
| crates/…/styles.rs | Shows the style document contract and public URL expansion. |
| crates/…/styles_static.rs | Shows the static image and overlay resource contract. |
| crates/…/sprites.rs | Shows sprite image, index, SDF, alias, and cache behavior. |
| crates/…/fonts.rs | Shows glyph range delivery and content encoding negotiation. |
| crates/…/admin.rs | Shows catalog and root administration responses. |
| crates/…/cache.rs | Shows the optional cache purge action. |
| martin/…/srv.rs | Defines public path and optional endpoint settings that shape the HTTP contract. |