3 Star 1 Fork 0

JinXue / porgi

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Porgi

Porgi is a lightweight web server written in C++ with a Python interface.

Requirements

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

Compile Porgi

git submodule init
git submodule update
mkdir build && cd build
cmake .. && make

Usage

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.

MIT License Copyright (c) 2017 Jin Xue Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

使用Python接口的轻量级web服务器 展开 收起
C++
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C++
1
https://gitee.com/jimxue/porgi.git
git@gitee.com:jimxue/porgi.git
jimxue
porgi
porgi
master

搜索帮助