Giter Club home page Giter Club logo

flask-api-example's Introduction

flask-api-example

Example of a basic API for a sqllite3 database

###Usage###

The file app.py demonstrates CRUD operations for a table called 'messages' that has two text columns, 'name' and 'comment'.

When the app launches it will check if the database tables already exist, and create them if necessary.

Routes:

RouteMethodParametersResult (JSON)
/GETReturns 'hello world'
/messagesGETReturns all messages
/messagesPOSTname=foo&comment=barCreates a new message with the posted values
/searchGETname=fooReturns all messages where name = 'foo'
/messages/1GETGets the message with id=1
/messages/1POSTname=foo&comment=barUpdate the message with id=1
/messages/1DELETEDelete the message with id=1

To deploy a database on the web using this file:

  1. Update app.py according to the tables you want in your database. Specifically, you should change the db_init() function so that it creates one or more table(s) with the rows/datatypes you would like. See here for a list of sqllite3 data types.
  2. Create an account at Python Anywhere. The URL for your app will default to username.pythonanywhere.com.
  3. At the Python Anywhere welcome screen, click I want to make a web app.
  4. Click the Web tab.
  5. Click Add a new web app
  6. Click Next in the wizard.
  7. Click Flask.
  8. Edit the text in the Path box to /home/[your user name]/app.py
  9. Click Next. Wait while the app is created. This may take a minute.
  10. Click the Files tab.
  11. Click the edit button next to app.py
  12. Replace the contents of their app.py file with yours, then click Save
  13. In the Web tab, click Reload
  14. The app should now be up and running. To test, go to http://yourname.pythonanywhere.com/ and make sure you see "Hello World". Then go to http://yourname.pythonanywhere.com/messages and verify that you see an empty array [] (since no messages have been added yet).

###Demo### http://krushton.pythonanywhere.com

flask-api-example's People

Contributors

krushton avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.