Giter Club home page Giter Club logo

rest_api-rocket-rust's Introduction

A very basic web server built on top of the Rocket web framework using Rust

This web server is a very basic implementation of a REST API server built on top of the Rocket web framework using Rust, where the user can add, delete and get items from a To-Do list.

Useful links

Useful toolchain extensions

  • Recommended extension to install that watching and auto-reloading of the application through the use of cargo watch:

    cargo install cargo-watch

Useful VSCode extensions

Compiling and Starting the Server

  • To compile for development:

    cargo build

    This creates a binary in the target/debug/rest_api-rocket-rust directory.

  • If cargo-watch is installed, then the following command can be used to compile and start the server:

    cargo watch -x run

    which will create the corresponding binary in target/release:

    target/release/rest_api-rocket-rust

    This will create a file data.sqlite in the root directory of the project.
    The server will, by default, start an HTTP API server on port 8000 and will only be accessible as localhost.

Sending requests to the server

  • To send a request to the server, use the following command in your terminal after starting the server:

    curl localhost:8000

    This will return the following response:

    {
      "message": "Hello, world!"
    }
    curl localhost:8000/todo

    This will return the following response:

    {
      "items": []
    }

    This will empty for the first time, since we have not added any items to the list yet.

  • To add an item to the list, use the following command:

    curl localhost:8000/todo -X POST -d '"Item number 1"' -H "Content-Type: application/json"

    This will return the following response:

    {
      "message": "1 rows inserted"
    }
  • To get the list of items, use the following command:

    curl localhost:8000/todo

    This will return the following response:

    {
      "items": [
        {
          "id": 1,
          "item": "Item number 1"
        }
      ]
    }
  • To delete an item from the list, use the following command by specifying the id of the item:

    curl localhost:8000/todo/1 -X DELETE

    This will return the following response:

    {
      "message": "1 rows deleted"
    }

rest_api-rocket-rust's People

Contributors

sumit03guha avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

ewanyonyi

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.