Last active
April 11, 2017 22:28
-
-
Save onjin/539664fd9457580a69d523997e4654a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
Simple json server. | |
echo '{"data": "some"}' > p1.json | |
python -m jsonserver | |
curl http://localhost:8000/p1 | |
""" | |
from SimpleHTTPServer import SimpleHTTPRequestHandler, test | |
class JsonServer(SimpleHTTPRequestHandler): | |
def _set_headers(self): | |
self.send_response(200) | |
self.send_header('Content-type', 'application/json') | |
self.end_headers() | |
def do_GET(self): | |
if '.' in self.path: | |
return SimpleHTTPRequestHandler.do_GET(self) | |
self.path += '.json' | |
return SimpleHTTPRequestHandler.do_GET(self) | |
if __name__ == "__main__": | |
test(HandlerClass=JsonServer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment