Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
5f1a422
add FastAPI uvicorn
Kilo59 Mar 21, 2020
8166a4d
define app
Kilo59 Mar 21, 2020
d79965e
create provisional models
Kilo59 Mar 22, 2020
cd64e47
define latest, location endpoints
Kilo59 Mar 22, 2020
21f4472
update models
Kilo59 Mar 22, 2020
b362750
change model name to match pre-existing model
Kilo59 Mar 22, 2020
033d924
defaults
Kilo59 Mar 22, 2020
b1a4742
update versions and response models
Kilo59 Mar 22, 2020
bdae7f0
divide sections
Kilo59 Mar 22, 2020
825de31
create middleware to attach the "data_source"
Kilo59 Mar 22, 2020
e31aad6
validation exception handler
Kilo59 Mar 22, 2020
20c49c2
get location by id
Kilo59 Mar 22, 2020
1cfdc2c
WIP get_all_locations
Kilo59 Mar 22, 2020
e8e50e8
add Totals
Kilo59 Mar 22, 2020
94a2f4e
Mount v2 of the application
Kilo59 Mar 22, 2020
091b461
add FIXME for timelines
Kilo59 Mar 22, 2020
ce9374c
end of file newlines
Kilo59 Mar 22, 2020
0d2f5f3
move models to models.py
Kilo59 Mar 22, 2020
04a35d8
exclude unset
Kilo59 Mar 22, 2020
6ecbc26
gunicorn with FastAPI
Kilo59 Mar 23, 2020
43bdeb0
change version name
Kilo59 Mar 23, 2020
86617e6
create Sources enum
Kilo59 Mar 23, 2020
21e952c
expose v1 and v2 apis via mounted WSGI app
Kilo59 Mar 23, 2020
0a2a262
lock dependencies for linux machines
Kilo59 Mar 23, 2020
8a19959
specify python 3.8 runtime for Heroku
Kilo59 Mar 23, 2020
3009428
Merge pull request #2 from ExpDev07/master
ExpDev07 Mar 23, 2020
85e493f
Merge pull request #3 from Kilo59/master
ExpDev07 Mar 23, 2020
9d22cd5
Fast api conversion (#4)
Kilo59 Mar 23, 2020
49800c3
Merge branch 'master' into FastAPI-conversion
Kilo59 Mar 23, 2020
ab817bd
add sources
Kilo59 Mar 24, 2020
ece30f3
update prefix
Kilo59 Mar 24, 2020
aec80ac
use separate v2 router
Kilo59 Mar 24, 2020
1949bea
add sources and make Timelines a boolean
Kilo59 Mar 23, 2020
f7b7354
fixed wrong date format and timelines appearing null
Mar 24, 2020
0ba6749
Merge pull request #6 from ExpDev07/master
ExpDev07 Mar 24, 2020
fe60577
Merge pull request #7 from ExpDev07/master
ExpDev07 Mar 24, 2020
7a0d38c
Merge pull request #8 from ExpDev07/master
ExpDev07 Mar 24, 2020
f0e36a2
replace Flask based v2
Kilo59 Mar 24, 2020
5202876
Fix existing tests
Kilo59 Mar 24, 2020
129a153
add api_client testing client fixture and basic swagger doc tests
Kilo59 Mar 24, 2020
d343a35
add Swagger information to the Readme
Kilo59 Mar 24, 2020
8b7d299
Improve middleware.
ExpDev07 Mar 24, 2020
2a6892b
fix tests
Mar 24, 2020
6b4447b
cleanup and use single quotes to follow same conventions
Mar 24, 2020
1dd1cf0
fixes source middleware not returning 404 when invalid source is prov…
Mar 24, 2020
a0542f2
add county to Country model
Kilo59 Mar 25, 2020
8978af1
test /locations codes
Kilo59 Mar 25, 2020
c7cb10c
better swagger description
Kilo59 Mar 25, 2020
2854739
forgot to import pytest
Kilo59 Mar 25, 2020
45dc4d4
add /latest test
Kilo59 Mar 25, 2020
304de58
changed start dev script to "pipenv run dev" and "pipenv run start" +…
Mar 25, 2020
88a6faf
fixed querying of all properties
Mar 25, 2020
a55e03e
update README with doc
Mar 25, 2020
0e3d352
small edit in models file
ExpDev07 Mar 25, 2020
d7d72d9
add github link
Mar 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Mount v2 of the application
  • Loading branch information
Kilo59 committed Mar 23, 2020
commit 94a2f4e8c0dee8ae7af34c2f8f52bfd923f5aefa
25 changes: 1 addition & 24 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@
from flask import Flask
from flask_cors import CORS

# See PEP396.
__version__ = '2.0'

def create_app():
"""
Construct the core application.
"""
# Create flask app with CORS enabled.
app = Flask(__name__)
CORS(app)

# Set app config from settings.
app.config.from_pyfile('config/settings.py');

with app.app_context():
# Import routes.
from . import routes

# Register api endpoints.
app.register_blueprint(routes.api_v1)
app.register_blueprint(routes.api_v2)

# Return created app.
return app
from .core import create_app
24 changes: 24 additions & 0 deletions app/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from flask import Flask
from flask_cors import CORS

def create_app():
"""
Construct the core application.
"""
# Create flask app with CORS enabled.
app = Flask(__name__)
CORS(app)

# Set app config from settings.
app.config.from_pyfile('config/settings.py');

with app.app_context():
# Import routes.
from . import routes

# Register api endpoints.
app.register_blueprint(routes.api_v1)
app.register_blueprint(routes.api_v2)

# Return created app.
return app
4 changes: 4 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import fastapi
import pydantic
import uvicorn
from fastapi.middleware.wsgi import WSGIMiddleware

from .data import data_source
from .core import create_app

# #################################
# Models
Expand Down Expand Up @@ -153,6 +155,8 @@ def get_all_locations(
def get_location_by_id(request: fastapi.Request, id: int, timelines: int = 1):
return {"location": request.state.source.get(id).serialize(timelines)}

# mount the existing Flask app to /v2
APP.mount("/v2", WSGIMiddleware(create_app()))
Copy link
Collaborator Author

@Kilo59 Kilo59 Mar 22, 2020

Choose a reason for hiding this comment

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

@ExpDev07
I'm not sure how this behaves with the /v1 endpoints. But (at least locally), the /v2 endpoints appear to be functional, including the redirect to the github page when hitting /v2.

Copy link
Owner

Choose a reason for hiding this comment

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

So FastAPI works with flask or? The v1 endpoints can be found at:

  1. https://coronavirus-tracker-api.herokuapp.com/all
  2. https://coronavirus-tracker-api.herokuapp.com/confirmed
  3. https://coronavirus-tracker-api.herokuapp.com/deaths
  4. https://coronavirus-tracker-api.herokuapp.com/recovered

I have checked the logs, and they are still in use by a lot of apps, so they need to work.

Copy link
Collaborator Author

@Kilo59 Kilo59 Mar 22, 2020

Choose a reason for hiding this comment

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

@ExpDev07
It's mashing v1 and v2 together 😦
So because /v1 and /v2 are defined into the same app, this appears to put both /v2 and /v1 behind the /v2 prefix.

In order to separate them, I believe I need to create 2 separate flask apps and mount them separately.
This should be relatively simple.

For example /confirmed is part of /v1, but I can access it locally at /v2/confirmed when it should be /v1/confirmed.

Copy link
Collaborator Author

@Kilo59 Kilo59 Mar 22, 2020

Choose a reason for hiding this comment

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

I probably need to do something like...

APP.mount("/v1", WSGIMiddleware(create_app("v1")))
APP.mount("/v2", WSGIMiddleware(create_app("v2")))

Copy link
Owner

@ExpDev07 ExpDev07 Mar 22, 2020

Choose a reason for hiding this comment

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

It should be /confirmed without any prefix :). Hmm, two different flask apps? Not really the biggest fan of that. FastAPI doesn't support blueprinting?

Copy link
Owner

@ExpDev07 ExpDev07 Mar 22, 2020

Choose a reason for hiding this comment

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

I mean if the old v1 endpoints work then, then I guess it's fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd be happy to get on a screen share, discord etc. to talk about this stuff (and deployment configuration, etc.).

Copy link
Owner

Choose a reason for hiding this comment

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

My Discord # is: Marius Big Ounce#2997.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just sent you an invite.
Kilo59#8819

Copy link
Owner

@ExpDev07 ExpDev07 Mar 22, 2020

Choose a reason for hiding this comment

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

I think I accidentally declined it (lol), sent you one now.


if __name__ == "__main__":
uvicorn.run(
Expand Down