• This repository has been archived on 09/Feb/2021
  • Stars
    star
    187
  • Rank 205,410 (Top 5 %)
  • Language
    Python
  • Created about 9 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿฆ Falcon REST API with PostgreSQL using ORM

Falcon REST API with PostgreSQL

Deploy

Simple REST API using Falcon web framework.

Falcon is a high-performance Python framework for building cloud APIs, smart proxies, and app backends. More information can be found here.

Requirements

This project uses virtualenv as isolated Python environment for installation and running. Therefore, virtualenv must be installed. And you may need a related dependency library for a PostgreSQL database. See install.sh for details.

Installation

Install all the python module dependencies in requirements.txt

  ./install.sh

Start server

  ./bin/run.sh start

Deploy

You need to set APP_ENV environment variables before deployment. You can set LIVE mode in Linux/Heroku as follows.

Linux

In Linux, just set APP_ENV to run in live mode.

export APP_ENV=live
./bin/run.sh start

Heroku

In Heroku, use the command config:set. (See here for details)

heroku config:set APP_ENV=live

Usage

Create an user

  • Request
curl -XPOST http://localhost:5000/v1/users -H "Content-Type: application/json" -d '{
 "username": "test1",
 "email": "[email protected]",
 "password": "test1234"
}'
  • Response
{
  "meta": {
    "code": 200,
    "message": "OK",
  },
  "data": null
}

Log in with email and password

  • Request
curl -XGET http://localhost:5000/v1/users/self/login -H "Content-Type: application/json" -d '{
 "email": "[email protected]",
 "password": "test1234"
}'
  • Response
{
  "meta": {
    "code": 200,
    "message": "OK"
  },
  "data": {
    "username": "test1",
    "token": "gAAAAABV-TpG0Gk6LhU5437VmJwZwgkyDG9Jj-UMtRZ-EtnuDOkb5sc0LPLeHNBL4FLsIkTsi91rdMjDYVKRQ8OWJuHNsb5rKw==",
    "email": "[email protected]",
    "created": 1442396742,
    "sid": "3595073989",
    "modified": 1442396742
  }
}

Check the validation of requested data

  • Request
curl -XPOST http://localhost:5000/v1/users -H "Content-Type: application/json" -d '{
 "username": "t",
 "email": "[email protected]",
 "password": "123"
}'
  • Response
{
  "meta": {
    "code": 88,
    "message": "Invalid Parameter",
    "description": {
      "username": "min length is 4",
      "email": "value does not match regex '[a-zA-Z0-9._-]+@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,4}'",
      "password": [
        "value does not match regex '[0-9a-zA-Z]\\w{3,14}'",
        "min length is 8"
      ]
    }
  }
}

Get database rollback error in response for duplicated data

  • Request
curl -XPOST http://localhost:5000/v1/users -H "Content-Type: application/json" -d '{
 "username": "test1",
 "email": "[email protected]",
 "password": "test1234"
}'
  • Response
{
  "meta": {
    "code": 77,
    "message": "Database Rollback Error",
    "description": {
      "details": "(psycopg2.IntegrityError) duplicate key value violates unique constraint \"user_email_key\"\nDETAIL:  Key (email)=([email protected]) already exists.\n",
      "params": "{'username': 'test1', 'token': 'gAAAAABV-UCq_DneJyz4DTuE6Fuw68JU7BN6fLdxHHIlu42R99sjWFFonrw3eZx7nr7ioIFSa7Akk1nWgGNmY3myJzqqbpOsJw==', 'sid': '6716985526', 'email': '[email protected]', 'password': '$2a$12$KNlGvL1CP..6VNjqQ0pcjukj/fC88sc1Zpzi0uphIUlG5MjyAp2fS'}"
    }
  }
}

Get a collection of users with auth token

  • Request
curl -XGET http://localhost:5000/v1/users/100 -H "Authorization: gAAAAABV6Cxtz2qbcgOOzcjjyoBXBxJbjxwY2cSPdJB4gta07ZQXUU5NQ2BWAFIxSZlnlCl7wAwLe0RtBECUuV96RX9iiU63BP7wI1RQW-G3a1zilI3FHss="
  • Response
{
  "meta": {
    "code": 200,
    "message": "OK"
  },
  "data": [
    {
      "username": "test1",
      "token": "gAAAAABV-UCAgRy-ee6t4YOLMW84tKr_eOiwgJO0QcAHL7yIxkf1fiMZfELkmJAPWnldptb3iQVzoZ2qJC6YlSioVDEUlLhG7w==",
      "sid": "2593953362",
      "modified": 1442398336,
      "email": "[email protected]",
      "created": 1442398336
    },
    {
      "username": "test2",
      "token": "gAAAAABV-UCObi3qxcpb1XLV4GnCZKqt-5lDXX0YAOcME5bndZjjyzQWFRZKV1x54EzaY2-g5Bt47EE9-45UUooeiBM8QrpSjA==",
      "sid": "6952584295",
      "modified": 1442398350,
      "email": "[email protected]",
      "created": 1442398350
    },
    {
      "username": "test3",
      "token": "gAAAAABV-UCccDCKuG28DbJrObEPUMV5eE-0sEg4jn57usBmIADJvkf3r5gP5F9rX5tSzcBhuBkDJwEJ1mIifEgnp5sxc3Z-pg==",
      "sid": "8972728004",
      "modified": 1442398364,
      "email": "[email protected]",
      "created": 1442398364
    }
  ]
}

More Repositories

1

kafka-learning

Go from Zero to Hero in Kafka
Shell
69
star
2

aws-csa

AWS Certificated Solutions Architect
19
star
3

efk-swarm

EFK (Elasticsearch, FluentBit, Fluentd, Kibana) with Docker Composer
Shell
8
star
4

strang-linear-algebra

Self-taught on Gilbert Strang's Linear Algebra
MATLAB
5
star
5

fluent-bit-docker-metadata

Lua script to parse Docker Swarm metadata for fluent-bit
Lua
5
star
6

airflow-boilerplate

Alpine based Airflow Boilerplate
Python
4
star
7

async-pipeline-bench

Simple http pipeline bench related to async with some Python frameworks ๐Ÿ
Python
4
star
8

django-sb-admin2-dark

HTML
4
star
9

koa-rest-api-docs

Terraform-Managed Koa RESTful API template to generate Redoc documentation and Swagger console
JavaScript
3
star
10

deep-learning-from-scratch

๋ฐ‘๋ฐ”๋‹ฅ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋Š” ๋”ฅ๋Ÿฌ๋‹ (์‚ฌ์ดํ†  ๊ณ ํ‚ค ์ง€์Œ, ๊ฐœ์•ž๋งต์‹œ ์˜ฎ๊น€)
Jupyter Notebook
2
star
11

ziwon.sh

Personal dotfiles
Shell
2
star
12

terraform-vpc-network

Terraform VPC Networking for Site-to-Site VPN with multiple VPCs
HCL
2
star
13

crawli

A simple crawler using go-colly
Go
2
star
14

dokkery

Docker Registry Event Handler for CI/CD
Go
2
star
15

ziwon

1
star
16

dotfiles-m1

dotfiles for 2021 and beyond
Shell
1
star
17

ziwon.github.io

Personal Blog
HTML
1
star
18

terraform-fluentd-aggregator

Terraform managed Fluentd aggregator on AWS Fargate
HCL
1
star
19

on-the-go

Learning Go Programming Language
Go
1
star
20

MySync

A MySQL Migration Utility (Schema and Stored Procedure)
Python
1
star
21

ziwon-hugo

My Hugo for Blogging with auto-deploying by Wercker
CSS
1
star
22

xdump

Simple Daily Pcap Saver written in Rust
Rust
1
star