From the course: Cloud Native Projects: GCP Serverless
Unlock this course with a free trial
Join today to access over 25,400 courses taught by industry experts.
Solution: Python - Google Cloud Platform Tutorial
From the course: Cloud Native Projects: GCP Serverless
Solution: Python
(upbeat music) - [Instructor] And now it's time for my solution to this challenge. Okay, so I created a file called "main.py" and in there I imported a few artifacts. So I imported random JSON and I used Flask because Flask is what GCP uses as a Python framework to handle all of the requests and responses. And I specifically wanted to return a 400 if no count was presented. Now, you may not have this. This is just how I chose to go about doing that. Do note that you'll need to have some sort of a requirements.text or have Flask installed on your machine if you're going to do that. So on line 6, we actually get into the problem set. So I define a function that takes a request. That function I spit out the JSON. From the request I get JSON element. And again, I'm looking for the count. And if the count exists, I set the count equal to that. If it does not exist, I return a 400 and I abort the function. That's a bad…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.