Giter VIP home page Giter VIP logo

api-first-axum's Introduction

api-first-axum

API-First with OpenAPI for Axum web framework

$ npx openapi-generator-cli generate -i ./petstore.yaml -g rust-axum -t ./templates -o ./petstore-api --additional-properties=packageName=petstore-api

Petstore-svc: simple implementation

  • Run example
$ cargo run -p petstore-svc
  • REST API call
$ curl localhost:3000/v1/pets

Petstore-db-svc: implementation with db

  • Run Postgres in docker
docker run \
    --name postgres \
    -p 5432:5432 \
    -e POSTGRES_USER=postgres \
    -e POSTGRES_PASSWORD=postgres \
    -e POSTGRES_DB=postgres \
    -d postgres
  • Edit .env file to provide DATABASE_URL

  • Install postgres libraries

sudo apt-get install libpq-dev
  • Install postgres cli for migrations
cargo install diesel_cli --no-default-features --features postgres
  • Run migrations
diesel migration run
  • Run App
$ cargo run -p petstore-db-svc
  • REST API PUT call

$ curl -X POST 'http://localhost:3000/v1/pets' \
  --header 'Content-Type: application/json' \
  --data-raw '{"id": 3, "name": "pet", "tag": "tag"}'

  • REST API GET call
$ curl localhost:3000/v1/pets

api-first-axum's People

Contributors

olegsmetanin avatar

Watchers

 avatar

api-first-axum's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.