Python is a little more refreshing, but The URL is not refreshing. Whoever you like.
sudo yum -y install python pip pip install redis
mkdir api; cd api
Edit ./cgi-bin/get.py as below (Put it under cgi-bin of python 2 system and execute permission chmod + x is required)
python -m CGIHTTPServer &
curl http://0.0.0.0:8000/cgi-bin/get.py?id="key"
{"items": "value"}
redis-cli > SET "key" "value"
get.py
#!/usr/bin/python
# coding: utf-8
import redis
import json
import cgi
form = cgi.FieldStorage()
print 'Content-Type: text/html\n\n'
if form.has_key("id"):
id=form["id"].value
r=redis.Redis()
value=r.get(id)
print json.dumps({'items':value})
Recommended Posts