Skip to Content
Cloud Native Python
book

Cloud Native Python

by Manish Sethi
July 2017
Intermediate to advanced
374 pages
8h
English
Packt Publishing
Content preview from Cloud Native Python

GET /api/v1/users

The GET/api/v1/users method shows the list of all users.

Let's create an /api/v1/users route by adding the following code snippet to app.py:

    @app.route('/api/v1/users', methods=['GET']) 
    def get_users(): 
      return list_users() 

Now that we have added the route, we need to define the list_users() function, which will connect with the database to get you the complete list of users. Add the following code to app.py:

    def list_users():    conn = sqlite3.connect('mydb.db')    print ("Opened database successfully");    api_list=[]    cursor = conn.execute("SELECT username, full_name,    email, password, id from users")    for row in cursor:    a_dict = {}    a_dict['username'] = row[0]    a_dict['name'] = row[1]    a_dict['email'] = row[2] a_dict['password'] ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python for DevOps

Python for DevOps

Noah Gift, Kennedy Behrman, Alfredo Deza, Grig Gheorghiu
Cloud Native

Cloud Native

Boris Scholl, Trent Swanson, Peter Jausovec

Publisher Resources

ISBN: 9781787129313Supplemental Content