pca9956b-api is an HTTP RESTful API designed to control PCA9956B devices. This repo includes: - An API specification in OpenAPI format. - Skeleton client and server implementations in Rust.
A fully-featured server implementation for Linux, in Rust, can be found at https://github.com/packom/pca9956b.
The text below was automatically generated by the openapi-generator.
To regenerate this skeleton client and server implementation, run openapi-generator over the API specification, and then apply the modifications listed here.
This client/server was generated by the [openapi-generator] (https://openapi-generator.tech) project. By using the OpenAPI-Spec from a remote server, you can easily generate a server stub. -
To see how to make this your own, look here:
This autogenerated project defines an API crate openapi_client
which contains:
* An Api
trait defining the API in Rust.
* Data types representing the underlying data model.
* A Client
type which implements Api
and issues HTTP requests for each operation.
* A router which accepts HTTP requests and invokes the appropriate Api
method for each operation.
It also contains an example server and client which make use of openapi_client
:
* The example server starts up a web server using the openapi_client
router,
and supplies a trivial implementation of Api
which returns failure for every operation.
* The example client provides a CLI which lets you invoke any single operation on the
openapi_client
client by passing appropriate arguments on the command line.
You can use the example server and client as a basis for your own code. See below for more detail on implementing a server.
Run examples with:
cargo run --example <example-name>
To pass in arguments to the examples, put them after --
, for example:
cargo run --example client -- --help
To run the server, follow these simple steps:
cargo run --example server
To run a client, follow one of the following simple steps:
cargo run --example client ClearError
cargo run --example client GErrors
cargo run --example client GetAddrEnabled
cargo run --example client GetAddrInfo
cargo run --example client GetAddrValue
cargo run --example client GetApi
cargo run --example client GetConfig
cargo run --example client GetCurrent
cargo run --example client GetError
cargo run --example client GetFreq
cargo run --example client GetGroup
cargo run --example client GetLedCurrent
cargo run --example client GetLedError
cargo run --example client GetLedInfo
cargo run --example client GetLedInfoAll
cargo run --example client GetLedPwm
cargo run --example client GetLedState
cargo run --example client GetOffset
cargo run --example client GetOutputChange
cargo run --example client GetOverTemp
cargo run --example client GetPwm
cargo run --example client GetSleep
cargo run --example client Reset
cargo run --example client SetAddrEnabled
cargo run --example client SetAddrValue
cargo run --example client SetConfig
cargo run --example client SetCurrent
cargo run --example client SetFreq
cargo run --example client SetGroup
cargo run --example client SetLedCurrent
cargo run --example client SetLedError
cargo run --example client SetLedInfo
cargo run --example client SetLedInfoAll
cargo run --example client SetLedPwm
cargo run --example client SetLedState
cargo run --example client SetOffset
cargo run --example client SetOutputChange
cargo run --example client SetPwm
cargo run --example client SetSleep
The examples can be run in HTTPS mode by passing in the flag --https
, for example:
cargo run --example server -- --https
This will use the keys/certificates from the examples directory. Note that the server chain is signed with
CN=localhost
.
The server example is designed to form the basis for implementing your own server. Simply follow these steps.
cargo init --bin
.openapi_client
into the members
array under [workspace] in the root Cargo.toml
, e.g., members = [ "openapi_client" ]
.openapi_client = {version = "0.1.0", path = "openapi_client"}
under [dependencies]
in the root Cargo.toml
.[dependencies]
and [dev-dependencies]
from openapi_client/Cargo.toml
into the root Cargo.toml
's [dependencies]
section.
[dev-dependencies]
, but only the [dependencies]
that are required by the example server. These should be clearly indicated by comments."optional = true"
from each of these lines if present.Each autogenerated API will contain an implementation stub and main entry point, which should be copied into your project the first time:
cp openapi_client/examples/server.rs src/main.rs
cp openapi_client/examples/server_lib/mod.rs src/lib.rs
cp openapi_client/examples/server_lib/server.rs src/server.rs
Now
src/main.rs
, remove the mod server_lib;
line, and uncomment and fill in the extern crate
line with the name of this server crate.src/main.rs
to src/lib.rs
and uncomment.let server = server::Server {};
line to let server = SERVICE_NAME::server().unwrap();
where SERVICE_NAME
is the name of the server crate.cargo build
to check it builds.cargo fmt
to reformat the code.Now replace the implementations in src/server.rs
with your own code as required.
Later, if the API changes, you can copy new sections from the autogenerated API stub into your implementation. Alternatively, implement the now-missing methods based on the compiler's error messages.