Skip to content

crespire/assessment_python_api

Repository files navigation

Why

This was a technical assessment I completed in October 2022. It is a Python project written with Flask.

Getting Started

  • System requirements
    • Python v3.9
  • Set up a virtual environment. Please refer to this document for how to use virtual environments.
  • Install dependencies
    pip install -r requirements.txt
    
  • Seed database
    python seed.py
    
  • Run dev server
    flask run --port=8080
    

Getting Started (Docker)

Instead of following the steps above, you can also use Docker to set up your environment.

  • System requirements
  • Run docker-compose up to spin up the dev server.
  • Enter Ctrl-C in the same same terminal or docker-compose down in a separate terminal to shut down the server.

Verify That Everything Is Set Up Correctly

You can use cURL or a tool like Postman to test the API.

Example Curl Commands

You can log in as one of the seeded users with the following curl command:

curl --location --request POST 'localhost:8080/api/login' \
--header 'Content-Type: application/json' \
--data-raw '{
    "username": "thomas",
    "password": "123456"
}'

Then you can use the token that comes back from the /login request to make an authenticated request to create a new blog post

curl --location --request POST 'localhost:8080/api/posts' \
--header 'x-access-token: your-token-here' \
--header 'Content-Type: application/json' \
--data-raw '{
    "text": "This is some text for the blog post...",
    "tags": ["travel", "hotel"]
}'

Helpful Commands

  • black . : Runs auto-formatter.
  • flask test : This repository contains a non-comprehensive set of unit tests used to determine if your code meets the basic requirements of the assignment. Please do not modify these tests.
  • python seed.py : Wipes existing data and populates the database with sample data.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages