https://github.com/morphisdom/morphapiwrapper
Wrapper functions for creating APIs in Morphisdom
https://github.com/morphisdom/morphapiwrapper
flask grpc morphisdom python restapi
Last synced: about 2 months ago
JSON representation
Wrapper functions for creating APIs in Morphisdom
- Host: GitHub
- URL: https://github.com/morphisdom/morphapiwrapper
- Owner: morphisdom
- License: mit
- Created: 2022-09-15T01:50:10.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-09-20T13:53:49.000Z (over 3 years ago)
- Last Synced: 2026-01-14T11:48:32.780Z (5 months ago)
- Topics: flask, grpc, morphisdom, python, restapi
- Language: Python
- Homepage:
- Size: 42 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# morphapiwrapper
### Wrapper functions for creating APIs in Morphisdom
[](https://travis-ci.org/joemccann/dillinger)
The morphapiwrapper package contains the wrapper functions to build a API for morphisdom
### Get started
You can install the package by running the following command
```python
pip install morphapiwrapper
```
Then load the package in Python by running the following command
```python
from morphapiwrapper import app, addapproute
```
### Write your custom function
You can write your custom function with this package and serve it as an API in morphisdom
Your custom function should always take two arguments. Namely _requestdata_ and _filereaderwriter_.
_requestdata_ is the variable which would get the data passed during the API call for the client.
For multiargument API in morphisdom _requestdata_ holds a list whose elements corresponds to individual arguments of the API function in sequence.
However _requestdata_ can also hold string, number, boolean (for single argument API) and dictionary.
_filereaderwriter_ is an handle for downloading GCS or remote HTTP content into localdirectory.
if _requestdata_ contains and GCS file URI or HTTP url then the funtion _filereaderwriter.download_input_data(requestdata)_ downloads all those files and returns the name of the local files in the same order. The number of elements in _requestdata_ and _downloadeddata_ remains same.
The following function demonstrates a simple function to be served as a Morphisdom API.
The _requestdata_ is downloaded and returned as output.
In order to log billing API calls the billunit needs to be set greater than 0.
```python
def testfunction(requestdata,filereaderwriter):
downloadeddata = filereaderwriter.download_input_data(requestdata)
print(downloadeddata)
billunit = 2
return downloadeddata,billunit
```
### Wrap your function
Once your function is created wrap your function in an flask app with the following code snippet
```python
app = addapproute(app, testfunction)
```
The returned app is a flask app which has a route _/testfunction_ added in it.
On calling this route _testfunction_ is executed