https://github.com/meain/synapse
Easily make python function into a rest api. Just add a wrapper `@synapse`
https://github.com/meain/synapse
Last synced: 23 days ago
JSON representation
Easily make python function into a rest api. Just add a wrapper `@synapse`
- Host: GitHub
- URL: https://github.com/meain/synapse
- Owner: meain
- Created: 2018-05-02T07:36:59.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-13T06:44:02.000Z (almost 7 years ago)
- Last Synced: 2025-02-09T00:18:02.116Z (3 months ago)
- Language: Python
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Synapse
A super simple way to convert your python function into a rest api.
*Python is simple, flask is simpler, synapse is even simpler*
**Falsk with better defaults**
> Not sure if this needed though. Might be micro optimizing. Most probably
## Model
- accepts json ( only json for now )
- passes each key to corresponding function arguments
- returns dict returned back as json## Deps
- `flask`
- `flask_cors`## Sample usage
```python
from synapse import Synapsesynapse = Synapse()
@synapse.connect('/robo')
def robo(name, robot=False):
if robot:
return f"{name} is a robot"
else:
return f"{name} is not a robot"synapse.start()
```### Ideal condition
For this if you send
```bash
curl --header "Content-Type: application/json" \
--request POST \
--data '{"name": "meain", "robot": true}' \
http://localhost:8080/robo
```
you get
```js
{
"data": "meain is a robot",
"success": true
}
```### Error condition
It has basic error check for now. So if you send
```bash
curl --header "Content-Type: application/json" \
--request POST \
--data '{"nxame": "meain"}' \
http://localhost:8080/robo
```you get
```js
{
"error": "Keys ['name'] not found",
"success": false
}
```## TODO
> For TODO check `todo/`