Skip to content

SCUACM/api-workshop-2025

Repository files navigation

API Workshop 2025

Follow-along tutorial for ACM's API workshop 10/14/2025

Things you'll need

Accessing ACM's API

For our first task, we will be getting familiar with calling APIs in Postman, an industry standard tool used for getting data from APIs. we will be pinging the endpoints implemented in this GitHub repo

  1. Prove that you can access the API by typing https://api.scuacm.com/ in a web browser

API endpoint

  1. We want to access https://api.scuacm.com/v1/data to get our data, which we cannot do without a token, which we cannot do in a web browser

Data Error

  1. Open Postman after signing in and click the "Import APIs and collections" button

Postman Import

  1. The imported collection has 3 GET requests, which will get the data we need to access /v1/data. First, run the GET request "Confirm API" and see that the response at the bottom is the same as the web browser

Postman Confirm

  1. We need to get a token before getting our data, but just running the "Get Token" (/v1/token) request won't work. Click on the "API Workshop 2025" folder, click on the "Variables" tab and fill in the key value with "acmKey123"
    1. In a real API, you would get the token when signing up for an account on the provider's website, and is usually something you should keep secret!

Postman Variables

The Postman collection is set up to automatically take the key variable and insert it into the request as a URL query

Postman Token

  1. Now, we can run the "Get Data" request to finally get access to our "sensitive" data
    1. The token we got will be used as a Bearer token in the next request, which is a way to send strings securely, and is automatically configured in the Postman collection

The Postman collection has a script to automatically assign the output of the response to the token variable, where you can note the response.json() and data.token snippets, which you can also use to save responses to variables in your own code

Postman Script

Postman Data

Making Proxy APIs with Python

Now, to get data from APIs to use in your apps, you'll likely need a proxy API to avoid CORS issues (explained in the slides). Therefore, we need to create our own API that acts as a middleman between your app and the data you want. The simplest way is to use the Flask library with Python due to it's simplicty and powerful things that Python can do, such as data manipulation with NumPy.

Setup

First, we need to set up your Python environment to be able to run the server.py file

  1. In your terminal (Ctrl + ~ in VSCode) run the following command:
    1. Windows - py -m venv venv
    2. Mac/Linux python3 -m venv venv
  2. This creates a Python virtual environment in the venv folder, which keeps any packages installed local to this folder
  3. To activate the virutal environment, enter the following in the terminal:
    1. Windows - .\venv\Scripts\activate
    2. Mac/Linux - source venv/bin/activate
    3. You should see (venv) in your terminal from here on out. Whenever you want to run anything, make sure that is there
  4. Now, we need to install the packages in order to run the file. This repo has a requirements.txt, which you can use to define packages to install instead of manually doing them. Install with the following command:
    1. pip install -r requirements.txt
    2. pip is the Python package manager

Code Breakdown

Everything has now been set up. Before running server.py, let's break down some of the functionality of the Flask app

Python Code 1

Python Code 2

Python Code 3

Python Code 4

Python Code 5

Running the Flask server

To run the server, type the following command in the terminal: python server.py

You can now navigate to http://127.0.0.1:3000 to access you server! To get to the other endpoints, type the one you want (ex: /add) after the url with the required parameters

Challenge

The acm-data endpoint requires a JSON body, which cannot be done in a browser. Your task is to:

  1. Create a new Postman request and set it to POST
  2. Set the body to raw and type to JSON
  3. Fill in the body with the JSON format it needs, with a valid ACM token
  4. You should see the success message

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages