Skip to content

jgmuchiri/resources_api

 
 

Repository files navigation

Operation Code Learning Resources API

Vision

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.

Getting Started

Sometimes these installs can be tricky. If you get stuck ask for help in the Slack #oc-python-projects channel!

  1. 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.
  1. Fork & Clone
  1. Install Docker Mac and Windows or Linux and ensure it is running
  1. 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)
  2. Run make setup
  3. Run make all and 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.

Authentication

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:

  1. 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

  1. 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"
}
  1. 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/"
}'

Development Notes

If you make changes to the models.py or other schemas, you need to run a migration and upgrade again:

make migrate

Before committing, please lint your code:

make lint

About

API for programming and cyber security learning resources

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 94.8%
  • Makefile 3.3%
  • Other 1.9%