Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
plusk-dev committed Jun 19, 2021
0 parents commit 7d7d6ac
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "venv\\Scripts\\python.exe"
}
37 changes: 37 additions & 0 deletions README.md
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.
2 changes: 2 additions & 0 deletions json_server/__init__.py
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 added json_server/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added json_server/__pycache__/main.cpython-38.pyc
Binary file not shown.
21 changes: 21 additions & 0 deletions json_server/main.py
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)
24 changes: 24 additions & 0 deletions setup.py
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"
)
3 changes: 3 additions & 0 deletions test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"status":200
}

0 comments on commit 7d7d6ac

Please sign in to comment.