Porgi is a lightweight web server written in C++ with a Python interface.
Porgi can only be built on Linux 2.6+. To build Porgi, these components are required:
On Ubuntu, these packages can be installed by:
apt-get install cmake libboost-python-dev python3 python3-dev
git submodule init
git submodule update
mkdir build && cd build
cmake .. && make
Porgi is very easy to use. A Python script is needed to tell Porgi how the requests should be handled.
@porgi.route('/hello') # specify what URL pattern this handler is responsible for
def hello(request):
# get information about the HTTP request
print(request.uri)
print(request.method)
print(request.headers['Host'])
# respond to the client
return porgi.make_response(200, {'Content-Type': 'text/plain'}, 'Hello world!')
# now with a bit of pattern matching
@porgi.route('/hello/:name')
def hello_with_name(request, params):
return 'Hello ' + str(params['name']) + '!' # returning a string also works
Run Porgi with this Python script:
porgi app.py
Now you can open your browser and visit http://localhost:8080/hello
or http://localhost:8080/hello/<your name>
.
By default Porgi listens on port 8080. If you want to assign port manually, use the -p <port>
option. Porgi supports multi-threading. The number of worker threads can be specified by the -n <ncpus>
option.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。