View Code? Open in Web Editor
NEW
This project forked from alexaorrico /airbnb_clone_v2
Extension of the project to include API routes using python-flask.
Shell 0.45%
Python 80.59%
CSS 7.25%
HTML 11.71%
airbnb_clone_v3's Introduction
airbnb_clone_v3's People
airbnb_clone_v3's Issues
Update DBStorage
and FileStorage
, adding two new methods. All changes should be done in the branch storage_get_count:
A method to retrieve one object:
Prototype: def get(self, cls, id):
Returns the object based on the class and its ID, or None if not found.
A method to count the number of objects in storage:
Prototype: def count(self, cls=None):
Returns the number of objects in storage matching the given class. If no class is passed, returns the count of all objects in storage.
Since the beginning we’ve been using the unittest module, but do you know why unittests are so important?
Because when you add a new feature, you refactor a piece of code, etc… you want to be sure you didn’t break anything.
The following requirements must be met for your project:
All current tests must pass (don’t delete them…)
Add new tests as much as you can (tests are mandatory for some tasks)
Create a new view for State objects that handles all default RESTFul API actions
Designers are really creative when they have to design a “404 page”, a “Not found”
Today it’s different, because you won’t use HTML and CSS, but JSON!
In api/v1/app.py
, create a handler for 404
errors that returns a JSON-formatted 404
status code response. The content should be: "error": "Not found"
Create a new view for Amenity
objects that handles all default RESTFul API actions
Create a new view for User
object that handles all default RESTFul API actions
Your first endpoint (route) will be to return the status of your API :
Create a folder api
at the root of the project with an empty file __init__.py
Create a folder v1
inside api
: this is where you will create the application file, methods, host and port parameters.
Create a folder views
inside v1
: this is where you will create the blueprint and views.
Create a new view for Review
object that handles all default RESTFul API actions.
CORS
A resource makes a cross-origin HTTP request when it requests a resource from a different domain, or port, than the one the first resource itself serves.
Why do we need this?
Because you will soon start allowing a web client to make requests your API. If your API doesn’t have a correct CORS setup, your web client won’t be able to access your data.
With Flask, it’s really easy, you will use the class CORS
of the module flask_cors
.
How to install it: $ pip3 install flask_cors
Update api/v1/app.py
to create a CORS
instance allowing: /*
for 0.0.0.0
Same as State, create a new view for City objects that handles all default RESTFul API actions
Create a new view for Place
objects that handles all default RESTFul API actions.
Create an endpoint that retrieves the number of each objects by type:
In api/v1/views/index.py
Route: /api/v1/stats
You must use the newly added count()
method from storage
NB: No need to have a pretty rendered output, it’s a JSON, only the structure is important