aboutsummaryrefslogtreecommitdiff
path: root/gn2/wqflask/requests.py
diff options
context:
space:
mode:
authorAlexander_Kabui2024-01-02 13:21:07 +0300
committerAlexander_Kabui2024-01-02 13:21:07 +0300
commit70c4201b332e0e2c0d958428086512f291469b87 (patch)
treeaea4fac8782c110fc233c589c3f0f7bd34bada6c /gn2/wqflask/requests.py
parent5092eb42f062b1695c4e39619f0bd74a876cfac2 (diff)
parent965ce5114d585624d5edb082c710b83d83a3be40 (diff)
downloadgenenetwork2-70c4201b332e0e2c0d958428086512f291469b87.tar.gz
merge changes
Diffstat (limited to 'gn2/wqflask/requests.py')
-rw-r--r--gn2/wqflask/requests.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/gn2/wqflask/requests.py b/gn2/wqflask/requests.py
new file mode 100644
index 00000000..43c8001f
--- /dev/null
+++ b/gn2/wqflask/requests.py
@@ -0,0 +1,16 @@
+"""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))