Streaming & Response Formats
Response formats
Section titled “Response formats”Endpoints that return a list of features take a format parameter:
| Value | Content-Type | Delivery | Description |
|---|---|---|---|
json (default) | application/geo+json | Sent in one piece | GeoJSON FeatureCollection. |
geojson | application/geo+json | Streamed in chunks | Same FeatureCollection, sent as it is produced. |
csv | text/csv | Streamed in chunks | Header row, then one row per feature with id, type, lat, lng and properties. properties is a JSON-encoded cell. |
ndjson | application/x-ndjson | Streamed in chunks | One GeoJSON Feature per line. |
json and geojson have the same shape. The difference is delivery: json waits until the response is complete, while geojson, csv and ndjson start arriving immediately. An unknown value returns a 422 validation_error.
These endpoints accept format:
| Endpoint | Notes |
|---|---|
/features | All four formats. |
/search | All four formats. |
/query | Applies to feature results. See below. |
/isochrone | Only when time or contours_meters has more than one value. A single budget always returns one Feature. |
/optimize | Applies to a solved result. An asynchronous job response (status: processing) is always JSON. |
/geocode, /geocode/reverse, /geocode/autocomplete | All four formats. |
/elevation | Only for MultiPoint lookups. A Point lookup returns one Feature. |
/route | Only when alternatives is greater than 0. Without alternatives the route is one Feature. |
/datasets/{id}/features | All four formats, one page at a time. The streamed formats send the next cursor in the X-Next-Cursor header only. See pagination. |
What /query returns
Section titled “What /query returns”A PlazaQL result is not always a FeatureCollection, and the shape follows the query:
- Feature results, such as
search(...), honorformat. - A single computed feature, such as
route(...)orisochrone(...), returns one GeoJSON Feature. .count(),.sum(),.avg(),.min(),.max()and.group_by(...)return a small JSON object such as{ "value": 12 }or{ "groups": {...}, "total": 3 }.matrix(...)returns the same object as/matrix.map_match(...)returns the same FeatureCollection as/map-match, with itsmatchingsarray.
A query with several named outputs returns { "outputs": { "name": ... } }, one value per output, each shaped as above. It only supports format=json. Any other format is a 400.
format has no effect on single features, counts, aggregates or matrices, because they aren’t lists of features. See response shapes for the full table.
/matrix, /map-match and /nearest have no format parameter.
When streaming matters
Section titled “When streaming matters”- Queries returning 1,000+ features
- Exporting data for offline processing
- Showing results incrementally in a UI
- Memory-constrained environments
For small result sets, just parse the response normally with the default json format. For large ones, ask for geojson, csv or ndjson so the response streams.
Streaming by language
Section titled “Streaming by language”Plaza responses are standard HTTP — use any streaming parser that works with chunked transfer encoding. Here’s what we recommend for each language and format.
JavaScript
Section titled “JavaScript”Browser (GeoJSON) — use oboe.js. It pattern-matches nodes inside a streaming JSON response, so you get each feature the moment it’s fully parsed:
import oboe from "oboe";
oboe({ url: "https://plaza.fyi/api/v1/features?within=-74.01,40.70,-73.97,40.75&tags[amenity]=cafe&format=geojson", headers: { "x-api-key": process.env.PLAZA_API_KEY },}) .node("features.*", (feature) => { console.log(feature.properties.name); return oboe.drop; // free memory after processing each feature }) .done(() => console.log("done")) .fail((err) => console.error("stream error:", err));Node.js (GeoJSON) — use jsonstream-next. Compose it with the fetch response body using stream.compose and async-iterate:
import { compose } from "node:stream";import JSONStream from "jsonstream-next";
const response = await fetch( "https://plaza.fyi/api/v1/features?within=-74.01,40.70,-73.97,40.75&tags[amenity]=cafe&format=geojson", { headers: { "x-api-key": process.env.PLAZA_API_KEY } },);
for await (const feature of compose(response.body, JSONStream.parse("features.*"))) { console.log(feature.properties.name);}CSV (Node.js) — use csv-parser. Same pattern:
import { compose } from "node:stream";import csvParser from "csv-parser";
const response = await fetch( "https://plaza.fyi/api/v1/features?within=-74.01,40.70,-73.97,40.75&tags[amenity]=cafe&format=csv", { headers: { "x-api-key": process.env.PLAZA_API_KEY } },);
for await (const row of compose(response.body, csvParser())) { console.log(row.name);}NDJSON (Node.js) — each line is a complete Feature, so you can split on newlines and parse as you go:
import readline from "node:readline";import { Readable } from "node:stream";
const response = await fetch( "https://plaza.fyi/api/v1/features?within=-74.01,40.70,-73.97,40.75&tags[amenity]=cafe&format=ndjson", { headers: { "x-api-key": process.env.PLAZA_API_KEY } },);
const lines = readline.createInterface({ input: Readable.fromWeb(response.body) });for await (const line of lines) { console.log(JSON.parse(line).properties.name);}Python
Section titled “Python”GeoJSON — use ijson. It yields objects matching a prefix path as they’re parsed from the stream:
import httpximport ijson
with httpx.stream( "GET", "https://plaza.fyi/api/v1/features", params={"within": "-74.01,40.70,-73.97,40.75", "tags[amenity]": "cafe", "format": "geojson"}, headers={"x-api-key": "your-key"},) as response: for feature in ijson.items(response.stream, "features.item"): print(feature["properties"]["name"])CSV — the standard library handles this. Wrap the streaming response in csv.DictReader:
import csvimport httpx
with httpx.stream( "GET", "https://plaza.fyi/api/v1/features", params={"within": "-74.01,40.70,-73.97,40.75", "tags[amenity]": "cafe", "format": "csv"}, headers={"x-api-key": "your-key"},) as response: reader = csv.DictReader(response.iter_lines()) for row in reader: print(row["name"])NDJSON — no extra library. Parse each line as it arrives:
import jsonimport httpx
with httpx.stream( "GET", "https://plaza.fyi/api/v1/features", params={"within": "-74.01,40.70,-73.97,40.75", "tags[amenity]": "cafe", "format": "ndjson"}, headers={"x-api-key": "your-key"},) as response: for line in response.iter_lines(): print(json.loads(line)["properties"]["name"])GeoJSON — Go’s standard library already streams JSON. json.NewDecoder reads from an io.Reader and decodes tokens incrementally — no extra dependency needed:
decoder := json.NewDecoder(resp.Body)
// Skip to the features arrayfor { t, err := decoder.Token() if err != nil { log.Fatal(err) } if t == "features" { decoder.Token() // opening bracket break }}
// Decode each Feature as it arrivesfor decoder.More() { var feature geojson.Feature if err := decoder.Decode(&feature); err != nil { log.Fatal(err) } fmt.Println(feature.Properties["name"])}CSV — use the standard library’s encoding/csv package. It reads records one at a time from any io.Reader:
reader := csv.NewReader(resp.Body)
header, _ := reader.Read() // first row is the headernameIdx := slices.Index(header, "name")
for { record, err := reader.Read() if err != nil { break } fmt.Println(record[nameIdx])}Use --no-buffer to see results as they arrive:
curl --no-buffer \ -H "x-api-key: $PLAZA_API_KEY" \ "https://plaza.fyi/api/v1/features?within=-74.01,40.70,-73.97,40.75&tags[building]=yes&format=geojson"Error handling
Section titled “Error handling”If the connection drops mid-response, your parser will see an unexpected EOF. To handle this:
- Track the last
osm_idyou processed. - Retry with a filter that excludes already-seen IDs, or use cursor-based pagination.
- If the same query consistently fails, add tighter spatial filters to reduce the result set.