Skip to content

isclub/flask-was

Repository files navigation

🍾 Flask extension for JSON API

中文版

This project is created and maintained by ISCLUB studio. Use the MIT license on GITHUB and PYPI

Introduction

Flask-was can better realize the separation of front and back ends. Quickly create data verification and check before the view function runs, generate data and return. You can also create user verification functions to data verification. Fast and elegant

Install

Use pip to install or update:

$ pip install -U flask-was

Example

A simple Signin

from flask import Flask
from flask_was import Was, Checker, Column

app = Flask(__name__)
api = Was(app)

api.addChecker(
    namespace="signin",
    obj=Checker(
        {
            "name": Column(api.String, biggest_str=20, smallest_str=4),
            "email": Column(api.EmailAddress, biggest_str=255, smallest_str=3),
            "password": Column(api.String, biggest_str=20, smallest_str=4),
        }
    ),
)


@app.route("/api/signin", methods=["POST"])
@api.checkeout("signin")
def api_signin(postdata):
    if postdata[0]:
        print("======== A new user coming ... ========")
        print("Name: " + postdata[1]["name"])
        print("Email: " + postdata[1]["email"])
        return api.send(json={"messages": "Signin was OK"}, status=200)
    else:
        return api.send(
            json={"messages": "Have some error. Check you forms", "postdata": postdata},
            status=400,
        )

app.run()

Post Request:

import requests

print(requests.post(
    "http://127.0.0.1:5000/api/signin",
    data={
        "name":"Flask",
        "email":"[email protected]",
        "password":"12345"
    },
).text)

Documentation

Read the documentation to get started. The documentation is in the /docs folder. If this project is helpful to you, please click the Star

Contribution Guide

If you find errors or have good suggestions, please refer to the following template to create issues and pull requests

  • Good ideas
## Introduction

What can this idea do ...

## Code

The files I changed and what did I do ...

## Info

Version Information...

Python: 3.6.x
Flask: 1.1.x
Flask-Was: 0.1.x

  • Problems in use
## Buiness

My business needs ...

## Code

Part of the code and full traceback ...

What does my code do ...

## Info

Version Information...

Python: 3.6.x
Flask: 1.1.x
Flask-Was: 0.1.x

If you make a useful contribution, you will be added to the contributors.md

License

MIT LICENSE