GithubHelp home page GithubHelp logo

gmh5225 / rust-crud-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from konkerama/rust-crud-api

0.0 0.0 0.0 37 KB

Rust CRUD web api using axum that targets mongodb and postgresdb

Shell 1.60% Rust 96.19% Dockerfile 2.21%

rust-crud-api's Introduction

Rust Crud api

Sample implementation of a rust web server using axum that integrates with posgresql and mongo db databases.

API Description

Exposes 2 separate crud implementations on /api/pg & /api/mongo for the PostgreSQL and MongoDB implementations respectively. You can list/create/update/delete customers by targeting the /api/pg path with attributes of customer_name & customer_surname in the request body. The same can be applied for MongoDB on the /api/mongo path.

Deployment

The application is packaged on a container for easy reuse on multiple environments. Liquibase is used for managing the PostgreSQL schema. The published containers exists here: https://hub.docker.com/repository/docker/konkerama/rust-crud-api

How to use

Prerquisites

Install rust on your system.

Test

cargo install sqlx-cli
./test.sh

Run API locally

docker compose up --build --force-recreate -V

docker compose performs the following steps:

  • builds the container
  • creates the mongodb and postgesql containers
  • creates and runs the liquibase containers that configures the postgresql schema
  • creates the pgadming and mongoexpress containers for easy debugging of the databases.

You can target the api using the following example curl commands:

# health check
curl http://localhost:8000/api/healthchecker -s | jq

# POST create customer 
curl -X POST http://localhost:8000/api/pg -d '{"customer_name": "john","customer_surname": "doe"}' -H "Content-Type: application/json" -s | jq

# GET customer (replace <id> with your customer id)
curl http://localhost:8000/api/pg/<id> -s | jq

# LIST customers
curl http://localhost:8000/api/pg -s | jq

# DELETE customer (replace <id> with your customer id)
curl -X DELETE http://localhost:8000/api/pg/<id> -s | jq

# PATCH customer (replace <id> with your customer id)
curl -X PATCH http://localhost:8000/api/pg/<id> -d '{"customer_name": "mark","customer_surname": "green"}' -H "Content-Type: application/json" -s | jq

# POST order
curl -X POST http://localhost:8000/api/mongo -d '{"customer_name":"mark", "product_name":"apple"}' -H "Content-Type: application/json" -s | jq

# LIST orders
curl http://localhost:8000/api/mongo -s | jq

# GET order (replace <id> with your order id)
curl http://localhost:8000/api/mongo/<id> -s | jq

# PATCH order (replace <id> with your order id)
curl -X PATCH http://localhost:8000/api/mongo/<id> -d '{"customer_name":"paul", "product_name":"banana"}' -H "Content-Type: application/json" -s | jq

# DELETE order (replace <id> with your order id)
curl -X DELETE http://localhost:8000/api/mongo/<id> -s | jq

Todo

  • implement tracing using opentelemetry
  • modify dependency loading with dotenv file rather than env vars

rust-crud-api's People

Contributors

konkerama avatar

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.