Rust API for rust-server-test
This spec is for testing rust-server-specific things
Overview
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:
- API version: 2.3.4
This autogenerated project defines an API crate rust-server-test which contains:
- An
Apitrait defining the API in Rust. - Data types representing the underlying data model.
- A
Clienttype which implementsApiand issues HTTP requests for each operation. - A router which accepts HTTP requests and invokes the appropriate
Apimethod for each operation.
It also contains an example server and client which make use of rust-server-test:
- The example server starts up a web server using the
rust-server-testrouter, and supplies a trivial implementation ofApiwhich returns failure for every operation. - The example client provides a CLI which lets you invoke any single operation on the
rust-server-testclient 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.
Examples
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
Running the server
To run the server, follow these simple steps:
cargo run --example server
Running a client
To run a client, follow one of the following simple steps:
cargo run --example client DummyGet
cargo run --example client DummyPut
cargo run --example client FileResponseGet
cargo run --example client HtmlPost
cargo run --example client RawJsonGet
HTTPS
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.
Writing a server
The server example is designed to form the basis for implementing your own server. Simply follow these steps.
- Set up a new Rust project, e.g., with
cargo init --bin. - Insert
rust-server-testinto themembersarray under [workspace] in the rootCargo.toml, e.g.,members = [ "rust-server-test" ]. - Add
rust-server-test = {version = "2.3.4", path = "rust-server-test"}under[dependencies]in the rootCargo.toml. - Copy the
[dependencies]and[dev-dependencies]fromrust-server-test/Cargo.tomlinto the rootCargo.toml's[dependencies]section.- Copy all of the
[dev-dependencies], but only the[dependencies]that are required by the example server. These should be clearly indicated by comments. - Remove
"optional = true"from each of these lines if present.
- Copy all of the
Each autogenerated API will contain an implementation stub and main entry point, which should be copied into your project the first time:
cp rust-server-test/examples/server.rs src/main.rs
cp rust-server-test/examples/server_lib/mod.rs src/lib.rs
cp rust-server-test/examples/server_lib/server.rs src/server.rs
Now
- From
src/main.rs, remove themod server_lib;line, and uncomment and fill in theextern crateline with the name of this server crate. - Move the block of imports "required by the service library" from
src/main.rstosrc/lib.rsand uncomment. - Change the
let server = server::Server {};line tolet server = SERVICE_NAME::server().unwrap();whereSERVICE_NAMEis the name of the server crate. - Run
cargo buildto check it builds. - Run
cargo fmtto reformat the code. - Commit the result before making any further changes (lest format changes get confused with your own updates).
Now replace the implementations in src/server.rs with your own code as required.
Updating your server to track API changes
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.
Documentation for API Endpoints
All URIs are relative to http://localhost
| Method | HTTP request | Description |
|---|---|---|
| **** | GET /dummy | A dummy endpoint to make the spec valid. |
| **** | PUT /dummy | |
| **** | GET /file_response | Get a file |
| **** | POST /html | Test HTML handling |
| **** | GET /raw_json | Get an arbitrary JSON blob. |
Documentation For Models
Documentation For Authorization
Endpoints do not require authorization.