Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EXPERIMENTAL FEATURE: API Overview Page #72

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

palnabarun
Copy link
Contributor

@palnabarun palnabarun commented Dec 8, 2017

Currently, the firefly application serves a json docs page at '/`.

The motive is to beautify that data in the form of HTML pages and add features such as trying out the API endpoint from the page itself.

TODO

[x] Add a basic for POC
[x] Deciding on a path to host the the page. Currently, it is at /index.html to prevent any conflicts \docs is finalized
--- Milestone 1 ---
[ ] Add support to firefly to accept an API name parameter through firefly.yml
[ ] Finalizing an API template according to optimal UX
--- Milestone 2 ---
[ ] Add testing features
--- Milestone 3 ---

More feature suggestions are welcome.

Attached

Preliminary UI for page
image

@anandology
Copy link
Member

Looks like we are using more and more of features of flask. I guess it is wise to start using flask rather than wasting our efforts reinventing each of those features.

@palnabarun
Copy link
Contributor Author

But do we need a full fledged web framework? We might just be using the templating feature of Flask which Jinja is very well providing us with.

@anandology
Copy link
Member

Already re-invented context globals, Jinja now and routing tomorrow.

Also I don't think your usage of jinja template is very effective. Creating FileSystemLoader everytime you need a template is expensive. Ideally, the template should be compiled on the first use and reused for subsequent calls. Flask takes care of it automatically.

@palnabarun
Copy link
Contributor Author

Okay. The loader can be instantiated once.

So what do you suggest? Modifying most things in firefly to use Flask? As routing is most probably the next feature that will be implemented.

Copy link
Member

@anandology anandology left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please look at my suggestions.

firefly/app.py Outdated
@@ -22,6 +23,10 @@
ctx = threading.local()
ctx.request = None

loader = FileSystemLoader(searchpath=get_template_path())
env = Environment(loader=loader)
template = env.get_template('index.html')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use PackageLoader instead computing the template path. See http://jinja.pocoo.org/docs/2.10/api/#basics.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! I didnt know about this. This is a robust abstraction.

firefly/app.py Outdated
functions = [
{'name': name, 'path': spec['path'], 'doc': spec['doc'], 'parameters': spec['parameters']}
for name, spec in self.generate_function_list().items()
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't the following line simple enough?

You are calling the function generate_function_list and that is returning a dictionary? Sounds confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generate_function_list was already there before. It's good that this was pointed out.

response.status = 200
response.text = html
return response

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't render_docs a better name for this function?

Copy link
Contributor Author

@palnabarun palnabarun Dec 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split this into layout.html and index.html.

Copy link
Contributor Author

@palnabarun palnabarun Dec 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that really needed? For future use cases?

firefly/utils.py Outdated
firefly_module = __import__('firefly')
file = firefly_module.__file__
return '/'.join(file.split('/')[:-1]) + '/templates'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comments in app.py about using PackageLoader.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants