Reputation: 5084
I'm using Flast Restplus for my API and I'm working on Swagger documentation. I split the API in multiple namespaces and I'm having a hard time to get the proper url:
activity.py:
activities_api = Namespace("activities", description="activities of the company", path='/')
class Activity(Resource):
def get(self):
pass
@activities_api.doc(params={'name': 'activity name'})
def post(self):
pass
@activities_api.doc(params={'ID': 'activity ID'})
def delete(self, activity_id):
pass
@activities_api.doc(params={'ID': 'ID de l\'activité'})
def put(self, activity_id):
pass
activities_api.add_resource(Activity, '/activities', endpoint='/')
api.py:
from activities import activities_api
app = Flask( __name__)
api = Api(app, prefix='/v1/', default = None, title='API', version='1.0', catch_all_404s=True)
api.add_namespace(activities_api)
In the home page I get the following paths:
PUT /v1/activities POST /v1/activities DELETE /v1/activities GET /v1/activities
When I make a curl GET to /v1/activities I get:
"GET /v1/activities / HTTP/1.1" 404 -
Should I use blueprints
with Namespaces
?
This is the structure of my API:
app.py
__init__.py
activities.py
simple as this, but the routes are wrong.
Upvotes: 3
Views: 1776
Reputation: 2088
There is only a minor mistake I think.
It is this line:
api = Api(app, prefix='/v1/', default = None, title='API', version='1.0', catch_all_404s=True)
Instead of saying prefix='/v1/'
, try prefix='/v1'
. Since when you add the extra /
to the end the url will point to /v1//activities
.
Upvotes: 2