feat: add the management API (readonly). Generate the OpenAPI spec #154
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
All the context is available in #153
Introduce a management API for Wasm Workers Server. For now, this API has only two endpoints:
/_api/v0/workers
: returns all the workers in the current project./_api/v0/workers/{id}
: returns the details of a worker like its configuration.Currently, workers doesn't have any associated identifier (ID). I'm generating it by computing the SHA256 of the
{project_root}/{file}
path.API Implementation
The API is split into two crates:
api-manage
: contains the source code of the API. It includes the models and the handlers. It exposes a method to configure an app service with these new methods. By default,wws
doesn't enable the management API.api-manage-openapi
: renders the OpenAPI specification from theapi-manage
and expose it. We will reuse this crate in the future to generate the CLI client in Rust (See Local panel to manage the current project #153).To define the OpenAPI spec, I'm using utoipa, an amazing crate to generate OpenAPI specifications from rust web frameworks like Actix. I only need to add annotations to the methods and models and it generates all the information.
Note that
utoipa
exposes the OpenAPI spec as an HTTP endpoint, but we don't want to expose it for now. That's the reason we're using theapi-manage-openapi
spec crate to generate it into a file. The process is done in thebuild.rs
file of that crate.