# API Pebble exposes an HTTP API that remote clients can use to interact with the daemon. The API has endpoints for starting and stopping services, adding configuration layers to the plan, and so on. The API uses HTTP over a Unix socket, with access to the API controlled by user ID. If `pebble run` is started with the `--http
` option, Pebble exposes a limited set of open-access endpoints (see {ref}`api-access-levels`) using the given TCP address. ## Using the API You can use different tools and clients to access the API. For more examples, see "How to use Pebble API". ### curl To access the API endpoints over the Unix socket, use the `--unix-socket` option of `curl`. For example: * TODO ``` curl ... ``` * TODO ``` curl ... ``` ### Go client To use the [Go client](https://pkg.go.dev/github.com/canonical/pebble/client) to access API endpoints over the Unix socket, first create a client using `New`, and then call the methods on the returned `Client` struct to interact with the API. For example, to stop a service named `mysvc`: ```go pebble, err := client.New(&client.Config{Socket: ".pebble.socket"}) if err != nil { log.Fatal(err) } changeID, err := pebble.Stop(&client.ServiceOptions{Names: []string{"mysvc"}}) if err != nil { log.Fatal(err) } _, err = pebble.WaitChange(changeID, &client.WaitChangeOptions{}) if err != nil { log.Fatal(err) } ``` We try to never change the underlying HTTP API in a backwards-incompatible way. However, in rare cases we may change the Go client in a backwards-incompatible way. For more information, see the [Go client documentation](https://pkg.go.dev/github.com/canonical/pebble/client). ### Python client The Ops library for writing and testing Juju charms includes a [Python client for Pebble API](https://ops.readthedocs.io/en/latest/reference/pebble.html). You can use the Python client to access the API endpoints over the Unix socket. For example: ```python import ops client = ops.pebble.Client('/path/to/.pebble.socket') client.start_services(['svc1', 'svc2']) ``` For more information, see: - [Source code of the Python client](https://github.com/canonical/operator/blob/main/ops/pebble.py) - [Pebble in the context of Juju charms](https://juju.is/docs/sdk/interact-with-pebble) ## Structure of the API Pebble requests use the `GET` method for reads and the POST method for writes. Some `GET` requests take optional query parameters for configuring or filtering the response, for example, `/v1/services?names=svc1` to only fetch the data for `svc1`. All data sent to the API in `POST` bodies and all response data from the API is in JSON format. Requests should have a `Content-Type: application/json` header. There are two main types of requests: synchronous ("sync"), and asynchronous ("async") for operations that can take some time to execute. Synchronous responses have the following structure: ```json { "type": "sync", "status-code": 200, "status": "OK", "result": "