hug is a module that makes it easy to create APIs in Python. mod_wsgi is a package for running Python code with Apache. By combining these, you can easily create an API that runs on Apache.
You need to have an application that supports WSGI in your Python code. application is prepared in hug, and it can be read as follows.
application = __hug_wsgi__
from hoge_hoge import __hug__wsgi__ as application
# -*- coding:utf-8 -*-
import hug
@hug.get("/", examples="text=Hello World!")
def keyword_extraction_api(text: hug.types.text):
return {'text': text}
application = __hug_wsgi__
Now send a request with http://hoge-server.com/text=Hello%20World!
and you will get{"text": "Hello World!"}
.
I was addicted to the fact that I couldn't execute the code.
The cause is that I wrote __hug_wsgi__
first.
(Maybe writing a decorator will add a method to __hug_wsgi__
? So it would be nice to write __hug_wsgi__
at the end.)
Recommended Posts