This project provides an API for storing and retrieving learning resources that might be helpful to members of Operation Code. Ideally, this project will provide the backend for various interfaces for working with the data. The first, and most important front end will be https://operationcode.org/resources.
Sometimes these installs can be tricky. If you get stuck ask for help in the Slack #oc-python-projects channel!
- Install Git.
- Choose your OS from the website and follow the prompts. This installs Git and the Bash Terminal on your machine.
- Extra: Git Documentation for more information on Git.
- Fork & Clone
- Fork a repository
- Create a local clone of your fork (Step 2 in the document above)
- Install Docker Mac and Windows or Linux and ensure it is running
- Linux: install docker compose as well.
- Install Make if you're on Windows. OSX already has it installed. Linux will tell you how to install it (i.e.,
sudo apt-get install make) - Run
make setup - Run
make alland then navigate to http://localhost:8000/api/v1/resources
If you see some JSON with a bunch of resources, it worked! If you encounter any errors, please open an issue or contact us on slack in #oc-python-projects.
Routes that modify the database (e.g., POST and PUT) are authenticated routes. You need to include a header in your request with your API key. To generate an API key:
- Send a POST to http://localhost:8000/api/v1/apikey with the following JSON payload:
{
"email": "your@email.com",
"password": "yoursupersecretpassword"
}The email and password specified should be your login credentials for the Operation Code website. If you are not a member of Operation Code, please sign up at https://operationcode.org/join
- The response will have the following structure (but will contain your email and apikey):
{
"apiVersion": "1.0",
"data": {
"apikey": "yourapikey",
"email": "your@email.com"
},
"status": "ok"
}- When you create a request to an authenticated route, you must include a header
x-apikey: yourapikey
Example curl request to an authenticated route:
curl -X POST \
http://127.0.0.1:8000/api/v1/resources \
-H 'Content-Type: application/json' \
-H 'x-apikey: 0a14f702da134390ae43f3639686fe26' \
-d '{
"category": "Regular Expressions",
"languages": ["Regex"],
"name": "Regex101",
"notes": "Regular Expression tester",
"paid": false,
"url": "https://regex101.com/"
}'If you make changes to the models.py or other schemas, you need to run a migration and upgrade again:
make migrateBefore committing, please lint your code:
make lint