Giter VIP home page Giter VIP logo

actix_web_api's Introduction

Actix Web Example Project

This project is a simple web application built with Actix Web, a powerful, pragmatic, and extremely fast web framework for Rust.

Features

  • Hello World: A simple route that responds with "Hello world".
  • User Management: Basic CRUD operations for user management.

Requirements

  • Rust 1.41 or higher
  • Cargo
  • MongoDB

Getting Started

To get started with this project, clone the repository and navigate into the project directory.

To start the project run:

cargo run

MongoDB Integration

This project uses MongoDB for persistent storage of user data, leveraging the MongoDB Rust driver for database operations within the Actix Web framework.

Setting Up MongoDB

Before running the application, ensure you have MongoDB installed and running on your system. You can download MongoDB from the official site and find installation instructions for your operating system.

Configuring MongoDB Connection

The application connects to MongoDB using the establish_connection function defined in the db module. This function initializes a MongoDB client and connects to a database named db. You can modify the database name and connection details (e.g., host, port) as needed in the src/db/connection.rs file.

Using MongoDB in the Application

The application's state (AppState) includes a MongoDB Database instance, which is passed to route handlers to perform CRUD operations on the users collection.

Example Usage

  • Create User: To add a new user, send a POST request to /users with a JSON body containing the user's details. For example:
curl -X POST http://localhost:8080/users -H "Content-Type: application/json" -d '{"id": 1, "name": "John Doe", "email": "[email protected]"}'
  • Get User: To retrieve a user by their ID, send a GET request to /users/{id}. Replace {id} with the actual user ID. For example:
curl -X GET http://localhost:8080/users/1
  • Update User: To update a user's details, send a PUT request to /users/{id} with a JSON body containing the updated user details. For example:
curl -X PUT http://localhost:8080/users/1 -H "Content-Type: application/json" -d '{"name": "Jane Doe", "email": "[email protected]"}'
  • Delete User: To delete a user by their ID, send a DELETE request to /users/{id}. Replace {id} with the actual user ID. For example:
curl -X DELETE http://localhost:8080/users/1

actix_web_api's People

Contributors

leandervdiepen avatar

Watchers

 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.