An open API service indexing awesome lists of open source software.

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`

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 Synapse

synapse = 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/`