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

POST api/v2/tweets

This function adds new tweets from an existing user.

In this case, we need to modify our add_tweet(new_tweet) method to interact with users, and the tweets collection in MongoDB to add new tweets, as follows:

    def add_tweet(new_tweet): 
     api_list=[] 
     print (new_tweet) 
     db_user = connection.cloud_native.users 
     db_tweet = connection.cloud_native.tweets 
     user = db_user.find({"username":new_tweet['tweetedby']}) 
     for i in user: 
       api_list.append(str(i)) 
     if api_list == []: 
      abort(404) 
     else: 
       db_tweet.insert(new_tweet) 
       return "Success" 

Now that we have modified the record, let's test it out. The following screenshot shows the success status of the POST request to add new tweets using POSTMAN:

Let's now validate whether the newly added ...

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