Skip to main content

🍾 Flask extension for JSON API

Project description

🍾 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={"messagess": "Signin was OK"}, status=200)
    else:
        return api.send(
            json={"messagess": "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":"flask@example.org",
        "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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_was-0.1.0.tar.gz (4.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page