1

I've installed Flask-Restless and am trying to run the quickstart app. All requests return a 404 error (both in the python logs and in the curl response). My whole setup is:

$ virtualenv venv --distribute
$ source venv/bin/activate
$ pip install flask-restless
$ pip install flask-sqlalchemy # it doesn't appear to do this automatically
... Copy code from quickstart to "run.py" ...
$ python ./run.py

(another window)
$ curl -i http://127.0.0.1:5000/

The console output from run.py is:

 * Running on http://127.0.0.1:5000/
 * Restarting with reloader
127.0.0.1 - - [16/Apr/2013 17:08:05] "GET / HTTP/1.1" 404 -

The test.db does get created, and using the debugger I can see that app.run() does execute.

Interestingly, I get exactly the same behavior with Eve. I am able to run simple Flask apps, however.

In case it matters, this is OS X 10.8 and Python 2.7.3.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610

1 Answers1

3

From the Flask-Restless documentation...

By default, the API for Person, in the above code samples, will be accessible at http://<host>:<port>/api/person, where the person part of the URL is the value of Person.__tablename__:

My guess is that by default, these frameworks do not set up an endpoint on the path /. They only have endpoints defined for paths related to actual objects in your API. Try the following...

curl -i http://127.0.0.1:5000/api/person
curl -i http://127.0.0.1:5000/person

These URLs might actually hit your endpoints that you're defining.

Mark Hildreth
  • 42,023
  • 11
  • 120
  • 109
  • Specifically it turns out to be `curl http://127.0.0.1:5000/api/person` (which is a little surprising; I didn't realize it would lowercase it). I had assumed that the root would give some kind of Django-style "here's the API." Thanks; this was a real help. The problem continues with Eve, but that means it's a problem with Eve, not my general setup. – Rob Napier Apr 16 '13 at 21:32
  • 1
    As I study the docs, the lowercasing comes from Flask-SQLAlchemy, which changes `CamelCase` to `camel_case`. – Rob Napier Apr 16 '13 at 21:37
  • **[Slight Unrelated] Beware of url_prefix and __tablename__** I spent three hours trying to figure out that. If you have a **model Person** For eg: ```person_blueprint = manager.create_api_blueprint(Person, methods=['GET', 'POST', 'DELETE'], url_prefix="/api") ``` You url should look like ```http://localhost:5000/api/person``` In my case, I created a blueprint this way ```person_blueprint = manager.create_api_blueprint(Person, methods=['GET', 'POST', 'DELETE'], url_prefix="/person") ``` wrong url_prefix caused a lot of 404 pain to me. – Mayur Rokade Jun 25 '15 at 10:06