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

PUT api/v1/users/[user_id]

This API function is used to update the attributes of the users in the MongoDB users collection.

In order to update the documents in the MongoDB user collection for a specific user, we will need to rewrite the upd_user(user) method as follows:

    def upd_user(user): 
     api_list=[] 
     print (user) 
     db_user = connection.cloud_native.users 
     users = db_user.find_one({"id":user['id']}) 
     for i in users: 
       api_list.append(str(i)) 
      if api_list == []: 
       abort(409) 
      else: 
       db_user.update({'id':user['id']},{'$set': user}, upsert=False ) 
       return "Success" 

Now that we have updated the method, let's test it on POSTMAN and check the response.

The following screenshot shows the response of the update API request using POSTMAN:

Let's validate the ...

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