# Services & SDK

**Declare the API once — as a versioned contract — and the server handler, the typed client, the OpenAPI spec, and the query layer all derive from that one object.** That is this pillar in a sentence. A [service](https://rickylabs.github.io/netscript/services-sdk/services/) implements the contract; the [SDK](https://rickylabs.github.io/netscript/services-sdk/sdk/) consumes it. Because both sides import the *same* contract object, a renamed field or a changed response shape is a compile error on both ends before it can ship — there is no hand-written client wrapper to keep in sync, and no separate "update the API docs" step.

That property is not hypothetical. In a production chat application built on NetScript, every dashboard data call goes through a typed client built directly off the contract type: adding a route to the channel contract makes it appear, fully typed, on the browser client with no extra wiring turn. The same discipline pays off whether the code is written by a teammate or an AI agent: one declared shape to read, one place to change it.

Use this pillar when you are defining a service, exposing OpenAPI or Scalar, or connecting a front end to a service without duplicating request and response types. Start with [Services & contracts](https://rickylabs.github.io/netscript/services-sdk/services/) for the server side, then [Typed SDK & client](https://rickylabs.github.io/netscript/services-sdk/sdk/) for the caller side; the type-flow theory lives in [Contracts](https://rickylabs.github.io/netscript/explanation/contracts/).

> TLS & HTTP/2 are opt-in
>
> A service listens over plain HTTP by default. Pass a
>
> tls
>
> option (
>
> ServiceTlsOptions { cert, key }
>
> as PEM strings) to
>
> defineService
>
> or the builder's
>
> .serve()
>
> — or set both
>
> NETSCRIPT_TLS_CERT_FILE
>
> and
>
> NETSCRIPT_TLS_KEY_FILE
>
> (file paths) — and the listener serves HTTPS and negotiates HTTP/2 via ALPN automatically. See
>
> Services → TLS & HTTP/2
>
> .

[Overview & Concepts   Contracts to service to client  The shared model for service handlers, OpenAPI, RPC, and typed clients.](https://rickylabs.github.io/netscript/netscript/explanation/contracts/) [Quickstart   Catalog service  Create the first service in the Storefront tutorial.](https://rickylabs.github.io/netscript/netscript/tutorials/storefront/02-catalog-service/) [How-To   Add a service  Add a new service to a workspace.](https://rickylabs.github.io/netscript/netscript/services-sdk/how-to/add-a-service/) [How-To   Discover services  Resolve service URLs and clients from the generated workspace.](https://rickylabs.github.io/netscript/netscript/services-sdk/how-to/discover-services/) [How-To   OpenAPI and Scalar  Expose the generated OpenAPI document and Scalar UI.](https://rickylabs.github.io/netscript/netscript/services-sdk/how-to/expose-openapi-scalar/) [API Reference   service and sdk  Generated service, SDK, and contract package symbols.](https://rickylabs.github.io/netscript/netscript/reference/service/)

## Learn, do, look up

[Learn  Storefront tutorial  Define contracts and services, then consume them through the typed SDK.](https://rickylabs.github.io/netscript/netscript/tutorials/storefront/) [Do  Recipes  Task-oriented recipes for this area, one problem each.](https://rickylabs.github.io/netscript/netscript/services-sdk/how-to/) [Look up  `@netscript/service` reference  Generated API reference. Related units: `sdk`, `contracts`.](https://rickylabs.github.io/netscript/netscript/reference/service/) [Understand  Contracts & type flow  The design rationale behind this pillar.](https://rickylabs.github.io/netscript/netscript/explanation/contracts/)
