We are going to create an app which will make an API call to http://jsonplaceholder.typicode.com/users and get a list of random users. Then our app will clean up the returned list of users and store them in a .json file.
- Import necessary library for making an API call.
- Make the API call to this URL ->
http://jsonplaceholder.typicode.com/users - Check the status code, return object (res.json())
- Wrap the API function in try/except block.
- Return the return object.
- Take the return object as parameter and transform the return object. (Before starting with transforming this return object, check its data type as it may not be a dictionary. Plan your code according to its data type)
- Create a new Python dictionary containing all 10 users and their details from the return object. (Items to be included: id, name, username, email)
- Return the Python dictionary
- Take a dictionary as the parameter
- Open up a new file (or create if it isn't existing)
- Dump the Python dictionary into this file
- Import all your modules
- Create the main app logic here
- Use a virtual environment.
- Create separate functions for all the steps.
- Modularize your code (either create a separate file for each function or create a file called
utils.pyand store all the functions in this file) - Wrap the necessary parts of your functions in try/except blocks.
- Create a
requirements.txtfile at the end of your project to store all the dependancy information. (pip freeze > requirements.txt)