Initial commit of cookiecutter based on https://christine.website/blog/how-i-start-rust-2020-03-15
This template produces a starter project for Rust that uses Rocket to serve an API and OKAPI to generate OpenAPI definitions for it. A Dockerfile is included.
It is based on the steps Christine Dodrill put together in this "How I Start" blog post. It sticks closely to those steps, so read the whole article to understand what's going on.
It assumes that you'll be using git
for source control and that you will have a remote repository you'd like to push to by default.
Make sure cookiecutter
is installed and up-to-date, either for your user or in a virtual environment:
pip3 install -U --user `cookiecutter`
Then run cookiecutter against this repository and answer the prompts:
cookiecutter https://git.sr.ht/~tuxpup/cookiecutter-rust-rocket-okapi
project_name [Hello Rocket]: Host Info Service
project_slug [host-info-service]:
executable_name [host-info-service]:
git_user [Name to use in git commits]: Joe Schmoe
git_email [Email to use in git commits]: joe@example.com
Select git_repo_host:
1 - github.com
2 - gitlab.com
3 - sr.ht
4 - other domain not listed
Choose from 1, 2, 3, 4 [1]: 3
git_repo_dns_name [sr.ht]:
git_repo_host_username [Username for your git remote repo]: tuxpup
project_url [https://sr.ht/~tuxpup/host-info-service]:
project_remote_url [git@sr.ht/~tuxpup/host-info-service]:
Using cargo: /home/geoff/.cargo/bin/cargo
Using git: /usr/bin/git
Configuring local git user name: Joe Schmoe
Configuring local git user email: joe@example.com
Setting git remote upstream to git@sr.ht/~tuxpup/host-info-service
Project generation complete.
Once cookiecutter finishes, change into the working directory and use cargo run
to confirm that everything builds and runs.
Point a browser to the generated UI for the API to see the generated OpenAPI schema.
Then from another terminal, try a few requests:
❯ curl http://localhost:8000/
Hello, world!%
❯ curl http://localhost:8000/hostinfo
{"hostname":"clamps","pid":97348,"uptime":141007}%
❯ curl http://localhost:8000/openapi.json
{
[... verbose output trimmed ...]
}
Or if you'd rather build a container:
docker build -t tuxpup/host-info-service .
docker run --rm -itp 8000:8000 tuxpup/host-info-service
and try those seame requests.
Many thanks to Christine Dodrill for the great "How I Start" article that inspired this.
Submit bugs/requests/complaints/comments here.