-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7d7d6ac
Showing
8 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"python.pythonPath": "venv\\Scripts\\python.exe" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# JSON Server | ||
|
||
## An tiny CLI to load data from a JSON File during development. | ||
|
||
<br> | ||
|
||
After installing `json-server` by | ||
|
||
``` | ||
pip install json_server | ||
``` | ||
|
||
You can run | ||
|
||
``` | ||
json_server <path-to-JSON-file> <port:optional> | ||
``` | ||
|
||
The port argument defaults to `5000` <br> | ||
|
||
This shall output: | ||
|
||
``` | ||
* Serving Flask app 'json_server.main' (lazy loading) | ||
* Environment: production | ||
WARNING: This is a development server. Do not use it in a production deployment. | ||
Use a production WSGI server instead. | ||
* Debug mode: on | ||
* Restarting with stat | ||
* Debugger is active! | ||
* Debugger PIN: 816-527-262 | ||
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) | ||
``` | ||
|
||
Which is similar to what a standard Flask app logs. | ||
|
||
Now that you have run the command, `http://127.0.0.1:<port>/` shall respond with your JSON. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from json_server.main import cli_command | ||
cli_command() |
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import click | ||
import json | ||
from flask import Flask | ||
from flask.json import jsonify | ||
from flask_cors import CORS | ||
|
||
app = Flask(__name__) | ||
CORS(app) | ||
|
||
@click.command() | ||
@click.argument('filename', type=click.Path(exists=True)) | ||
@click.argument('port', default=5000) | ||
def cli_command(filename, port): | ||
|
||
@app.route("/", methods=["GET"]) | ||
def index(): | ||
with open(click.format_filename(filename)) as file: | ||
contents = json.loads(file.read()) | ||
return jsonify(contents) | ||
|
||
app.run(debug=True, port=port) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from setuptools import setup, find_packages | ||
from os import path | ||
this_directory = path.abspath(path.dirname(__file__)) | ||
with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f: | ||
long_description = f.read() | ||
setup( | ||
name='json_server', | ||
version='0.1.3', | ||
packages=find_packages(), | ||
include_package_data=True, | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
install_requires=[ | ||
'click', | ||
'flask', | ||
'flask-cors' | ||
], | ||
entry_points={ | ||
'console_scripts': [ | ||
'json_server = json_server:cli_command', | ||
], | ||
}, | ||
url="https://github.com/YuvrajGeek/json-server" | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"status":200 | ||
} |