3

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.

1
  • How did you solve it? Commented May 15, 2020 at 20:45

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I tried that and I still get not found :( the data is not available on /v1//activities either
So, or I am totally misinterpreting your question or the code you posted above has no mistake in it. What I can say is that you saying endpoint='/' is not really doing anything but I don't think it is what causes the problem. You should certainly remove the / from /v1/.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.