Metadata-Version: 2.1
Name: flask-require
Version: 0.0.5
Summary: A simple Flask extension for requiring parameters in a request.
Author-email: Ivar Jönsson <ivajns-9@student.ltu.se>
License: MIT License
        
        Copyright (c) 2023 Ivar Jönsson
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: repository, https://github.com/ivario123/flask_require
Project-URL: source, https://github.com/ivario123/flask_require
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: flask (>=0.10.1)

# flask_require

This is a simple library to help you write cleaner flask code.

## Installation

```bash
pip install git+https://github.com/ivario123/flask_require
```

## Usage

```python
from flask import Flask,request
import require

app = Flask(__name__)

@app.route('/')
@require.fields(request)
def index(name):
    return f"Hello, {name}!"

if __name__ == '__main__':
    app.run()
```

### fields with optional response_formatter

```python
import flask
import require

app = flask.Flask(__name__)

def __response(name, description="", code=200):
    formatter_response = {"name": name, "description": description}

    return flask.make_response(dumps(formatter_response), code)

@app.route("/")
@fields(flask.request, response_formatter=__response)
def index(path):
    return {"name": "success", "description": "Works as it should"}

if __name__ == '__main__':
    app.run()
```

### Enforcing types

The system will check that the types provided in the signature and the types
provided by the caller are the same before passing the arguments to the function.

```python
from flask import Flask,request
import require

app = Flask(__name__)

@app.route('/')
@require.fields(request)
def index(name:str):
    return f"Hello, {name}!"

if __name__ == '__main__':
    app.run()
```

## Usage of admin

```python
from flask import Flask,request
from require import fields, admin

app = Flask(__name__)

@app.route('/')
@fields(request)
def index(name):
    return f"Hello, {name}!"

@app.route('/admin')
@admin()
def admin():
    return 'Hello, admin!'

def callback():
    print('Hello, callback!')

@app.route('/admin_with_callback')
@admin(callback)
def admin_with_callback():
    return 'Hello, admin with callback!'
```
