Crate pokedex_rs

Source
Expand description

§Rust Pokédex API 🦀

This project implements a simple web application that contains a CRUD API for a Pokédex - a database of Pokémons. It is meant as an experiment in building fully-working web applications in Rust.

This project includes several components usually found in modern web applications, including:

  • A high-performance HTTP server to handle incoming requests
  • A REST API with CRUD endpoints for Pokémon entities
  • Automatic serialization/deserialization of Pokémon entities as JSON
  • Automatic OpenAPI documentation including Swagger UI support (and others)
  • An ORM-like interface to persist Pokémons in a Postgres database
  • Support for managing and applying database migrations
  • Validation of incoming data at the endpoint level
  • Database connection pooling to improve performance
  • Configurable logging using a simple logging facade
  • Error handling with separation between service errors and their HTTP response counterparts
  • Support for development and production environments

This documentation is for the private lib crate implementing the types and functions required to implement the CRUD REST API for the Pokedex. For more details about the project, see the project’s GitHub repository.

§Notes

Pretty much everything in this crate is public. This would not normally be the case, but it was done for demo purposes, so that it’s easier to document the various pieces.

Re-exports§

pub use error::Error;
pub use error::Result;

Modules§

api
Types and functions used to implement the Pokedex REST API.
db
Helpers to connect to the Pokedex database. Currently supports Postgres as backend only.
error
Error type definition for our app.
helpers
Module containing various helper traits/functions/etc. used throughout the crate’s code.
models
Definition of entity models for the Pokedex app.
service_env
Information about the service’s runtime environment.
services
Service types used in the Pokedex app.

Macros§

forward_from
Generates From implementations that can be used to forward Into requests two level deep.
implement_pokemon_upsert
Macro to generate a struct used to insert or update a Pokemon in the database.
implement_pokemon_upsert_from
Macro to generate From implementations for insert/update Pokemon structs.
pokedex_app
Macro that expands to an App instance, initialized for our web application.

Functions§

configure_api
Allows registration of the entire Pokedex API under the /api scope.
get_json_config
Returns the JsonConfig to use for our service.
get_path_config
Returns the PathConfig to use for our service.
get_query_config
Returns the QueryConfig to use for our service.