Git Product home page Git Product logo

tornado-crud's Introduction

Basic CRUD Microservice in Python with Tornado

This is a basic CRUD microservice in Python with Tornado. It uses MongoDB as the database and Docker for local development.

1. Project Setup

Get the source code:

$ git clone https://github.com/thatsimo/tornado-crud
$ cd tornado-crud

$ tree .
.
├── README.md
├── app.py
├── docker-compose.yml
├── requirements.txt
├── run.py
├── tornado-crud.postman_collection.json
├── service
│   └── cats.py
└── test
    └── student_test.py

The directory service is for the source code of the service, and the directory test is for keeping the tests.

Setup Virtual Environment:

$ python3 -m venv .venv
$ source ./.venv/bin/activate
$ pip install --upgrade pip
$ pip3 install -r ./requirements.txt

Setup Local MongoDB:

$ docker-compose up -d

Setup Env Variables:

$ cp .env.example .env

You can run app and unit tests by either executing the tool directly or through run.py script. In each of the following, you can use either of the commands.

Server:

$ ./run.py server

Unit Tests:

$ ./run.py test

If you are able to run all these commands, your project setup has no error and you are all set for coding.


2. App

File app.py has business logic for CRUD operations for the students collection, it exposes routes to to serve various API endpoints, implemented through one Request Handler:

StudentHandler:

  • GET /students: gets all students
  • POST /students: create an entry in the students collection
  • GET /students/{id}: get the student entry with given id
  • PUT /students/{id}: update the student entry with given id
  • DELETE /students/{id}: delete the student entry with given id

You cant test the API endpoints using the Postman collection tornado-crud.postman_collection.json in the root directory.

tornado-crud's People

Contributors

thatsimo 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.