Post

That feeling when the API comes out sizzlin'

That feeling when the API comes out sizzlin'

Introduction

As you can see in the title, I made an API. Specifically to make an simple REST API in python than can validate if a student ID is real.

I first got this idea back in may when I found out that i’m in a microsoft group with every signle student in DSST. (So technically not my school but my school network)

So using dev tools and trying to figure out the api, I finnaly got all 12000 students student IDs!

Note: When downloading, I got more than just student ids. Thats why stuff is gonna be censored :)

So now I have all these Student IDs. Now what? Well this is when I remembered about my API idea from months ago so I went on figuring out how to make an API in the first place.

Coding!

I’m not totaly into coding so please don’t expect the best code from me. I also don’t use AI in my code because I believe that you don’t learn as well as doing it your self. Anyway I used fast api to make this because it is the easist way (for me) to make an api. At first it was super simple and it didn’t require a api key (I will talk more about this later), simply looked if the id was in the csv file (eg, if an sid of 123456 existed, 123456 would flag as exist, but 12 would also be flaged as exist.) It didn’t take forever to make this but after googling and reading random reddit threads, I now had a finished api! The code basically looked like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from fastapi import FastAPI, HTTPException

app = FastAPI()

keys = ["No_Key_For_You_:)"]

@app.get("/")
def search(sid: str, key: str | None = None):
    if key in keys:
        with open('sid.csv', 'r') as file:
            content = file.read()
        if sid in content.splitlines():
            return {"exist": "true"}
        else:
            return {"exist": "false"}
    else:
         raise HTTPException(status_code=401, detail="Unauthorized")

After that, I ran it, tested it, and now it is fully running on my home server!

Conclusion

It was fun learning how making this api and how to get all to work, I would like to thank TimMcCool for creating ScratchAttach, the whole reason why I mostly know about API’s and WeatherAPI for helping me get used to API’s.

This post is licensed under CC BY 4.0 by the author.

Trending Tags