Skip to main content

Module resources

Module resources 

Source
Expand description

Standalone waypoints and routes, on the wire.

Signal K’s own Resources API, at /signalk/v2/api/resources/waypoints and /signalk/v2/api/resources/routes – v2, not v1: the route registration (signalk-server/dist/api/resources/index.js, RESOURCES_API_PATH) is v2-only, and no v1 route exists at all. What a waypoint or route means to this workspace lives in waypoints and routes, the crates this module exists to serve; nothing here knows either crate exists, the same one-way dependency crate::stream already keeps toward signalk (units, not wire bytes), so that a wire-format module can be reused by a different domain crate later.

Both resource kinds answer the same four calls, registered by the same generic code on the server side (signalk-server/dist/api/resources/index.js builds identical routes for every resource type it knows about, waypoints and routes alike):

  1. GET /resources/{kind} – every one the server holds, keyed by UUID.
  2. POST /resources/{kind} – a new one; the server mints the UUID and returns it.
  3. PUT /resources/{kind}/{id} – creates or replaces one at a caller-chosen UUID. The server validates {id} as a proper UUID v4 (signalk-server/dist/api/resources/validate.js’s own uuid check); an id that is not refuses with 400 Invalid resource id provided, not a write.
  4. DELETE /resources/{kind}/{id} – removes it. Answers the same ActionResult shape PUT does (state/statusCode/message, the id echoed back in message on success), confirmed live against a real server.

A route’s own feature.geometry is a LineString, not a Point – the one real shape difference from a waypoint – and it may name each point along it via feature.properties.coordinatesMeta, an array aligned index-for-index with geometry.coordinates. Each entry is either {name} or {href} (the latter pointing at a standalone waypoint resource by uuid, so a route can be built from waypoints already in the library instead of bare positions); only the name variant is read or written here – linking route points back to waypoint resources is a feature of its own, not needed for this crate to carry a route it can round-trip.

There is no third, empty variant: each entry’s own TypeBox schema (resources-schemas.d.ts) is anyOf [{name}, {href}], not nullable, so a placeholder for an unnamed point in the middle of an otherwise-named route is refused outright, confirmed against a real server’s own AJV validation error. write_route writes coordinatesMeta only when every point carries a name, and leaves it out entirely otherwise.

Every write needs a token: unlike the stream, whose allowReadonly setting can let an unauthenticated client watch position updates, the REST interface refuses an unauthenticated write outright.

Structs§

Client
A client for one server’s own Resources API.
Route
A standalone route, as the wire carries it.
RoutePoint
One named point along a Route, as the wire carries it.
Track
A recorded track, as the wire carries it.
Waypoint
A standalone waypoint, as the wire carries it.