aboutsummaryrefslogtreecommitdiff
path: root/gn2/wqflask/requests.py
blob: 182201a5acf68af169a7627d46fad38928b1fc43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""requests but with monads"""
import requests
from pymonad.either import Left, Right, Either

def __wrap_response__(resp) -> Either:
    if resp.status_code == 200:
        return Right(resp)
    return Left(resp)

def get(url, params=None, **kwargs) -> Either:
    """Wrap requests get method with Either monad"""
    return __wrap_response__(requests.get(url, params=params, **kwargs))

def post(url, data=None, json=None, **kwargs) -> Either:
    """Wrap requests post method with Either monad"""
    return __wrap_response__(requests.post(url, data=data, json=json, **kwargs))


def put(url, data=None, json=None, **kwargs) -> Either:
    """Wrap requests put  method with Either monad"""
    return __wrap_response__(requests.put(url, data=data, json=json, **kwargs))


def delete(url,  **kwargs) -> Either:
    """Wrap requests delete  method with Either monad"""
    return __wrap_response__(requests.delete(url,  **kwargs))