Skip to content

Pochetes/portfolio-api

Repository files navigation

Roberto's Portfolio API

Software License Code Size Website Open Issues Closed Issues Lines of code

The Roberto's Portfolio API is meant to retrieve data about my college life, career experiences and more. The goal of this API is to provide a data source for my GraphQL backend to display information for my portfolio website.

Description

The api returns JSON responses in the applications/json format. It has a total of 6 endpoints that return specific data about me. More will be explained below.

File Structure

.
├── Dockerfile
├── LICENSE
├── Pipfile
├── Pipfile.lock
├── Procfile
├── README.md
├── api-tests.json
├── config.py
├── docker-compose.yml
├── endpoints
│   ├── __init__.py
│   ├── auth.py
│   ├── contacts
│   │   ├── README.md
│   │   ├── __init__.py
│   │   ├── models.py
│   │   └── routers.py
│   ├── experiences
│   │   ├── README.md
│   │   ├── __init__.py
│   │   ├── models.py
│   │   └── routers.py
│   ├── interests
│   │   ├── README.md
│   │   ├── __init__.py
│   │   ├── models.py
│   │   └── routers.py
│   ├── projects
│   │   ├── README.md
│   │   ├── __init__.py
│   │   ├── models.py
│   │   └── routers.py
│   ├── skills
│   │   ├── README.md
│   │   ├── __init__.py
│   │   ├── models.py
│   │   └── routers.py
│   ├── user
│   │   ├── README.md
│   │   ├── __init__.py
│   │   ├── models.py
│   │   └── routers.py
│   └── utils.py
├── main.py
├── media
│   └── gifs
│       ├── GETmethod.gif
│       ├── POSTmethod.gif
│       └── Params.gif
├── requirements.txt
└── script.sh

10 directories, 47 files

Technologies Used

The API is implemented in:

  • the Python language, using a framework known as FastAPI, which automatically renders a Swagger Documentation Spec.
  • MongoDB, the NoSQL database, in order to store all my data. Currently under the Python driver, Pymongo.
  • Uvicorn, a server implementation, that enables an ecosystem of Python web frameworks such as the one I'm currently using.
  • Pydantic, a data validation and settings management tool that helps define my models and schema more efficiently.

Features

This API provides many features that make it lighting-fast:

  • CORS Middleware
  • lru_cache Decorator
  • Easy-To-Use Documentation
  • Modularized Application
  • MongoDB CRUD Operations
  • Error & Exception Handling
  • Pylint & API Testing
  • Auth0 Authentication & Security
  • Built under Docker environment OS
  • Deployed On Heroku

Endpoints

The base URL is currently: https://robertos-api.herokuapp.com

User 👨🏼

You will be able to see my:

  • name.
  • email.
  • brief description.

See a detailed description at: User Docs

Contacts 📲

Here will be my social media links.

See a detailed description at: Contacts Docs

Skills 🌟

This section holds the technical skills that I possess.

See a detailed description at: Skills Docs

Experiences 📈

Here will be the experiences that I've had throughout my journey pursuing Software Engineering.

See a detailed description at: Experiences Docs

Interests 🤔

This will retrieve my interests in and outside the technology world.

See a detailed description at: Interests Docs

Projects 💡

This will return my software related projects that I have worked on.

See a detailed description at: Projects Docs

Documentation

Thanks to FastAPI, a documentation page is automatically rendered for us. This follows the OpenAPI Spec rules.

To see the docs, go to docs when it's deployed.

*Update: The /docs endpoint will automatically be accessed when using the base url.

Using a GET method

The GET method allows you to access all the data from a specific resource. It is done, like so:

GET method

Using a POST method

The POST method allows you to create a new data entry for a specific resource. There will be a Request body in which you will fill out all contents needed, like so:

POST method

Using a method that has a path parameter

A method that has a path parameter usually requires some sort of input to find, update, delete a specific resource. In this example, we are finding a single project by an id path parameter. To do this, copy the parameter from the first GET method and use it as the current path parameter, like so:

Params

Authentication

The POST, PUT, and DELETE endpoints are protected using 0Auth authentication. I am the only person that's able to make those changes (unless you were able to get my access token, that is) and authenticate the endpoints. It is secured through a JWT-formatted access token. After some time, a new token is generated, making it difficult for hackers to access these data points. The hashing algorithm used is RS256, or RSA Signature with SHA-256.

Configuration

To run this project, you need a couple things:

  • MongoDB connection
  • Virtual environment
  • Installed Dependencies

Get Project

You can clone this project using the following command:

Using HTTPS (I believe it's deprecated)

git clone https://github.com/Pochetes/portfolio-api.git

Using SSH

git clone [email protected]:Pochetes/portfolio-api.git

Database Connection

To get a MongoDB database, sign in (or create an account if you haven't already) to MongoDB Atlas. Then, create a new cluster and find the connection string in which you will put in a .env file, like so:

# Unix:
export MONGODB_URI = "mongodb+srv://Username:[email protected]/db-name?retryWrites=true&w=majority"

For more details, visit connect to a MongoDB database.

Creating a virtual environment

My application currently uses Pipenv to manage dependencies and environments, but you can also use pip + virtualenv.

To create a virtual environment, create a hidden virtualenv file, like so:

python3 -m venv name-of-env

Then, activate it, like so:

source name-of-env/bin/activate

Installing Dependencies

To install, run the command:

python3 -m pip install -r requirements.txt

Running the Server

To run the server, run:

python main.py

Creating a Docker Container

First, build the docker image as provided in the Dockerfile using this command:

docker build -t portfolio-api-image .

Afterwards, make a new container using the docker run command:

docker run -d \
--name portfolio-api-container \
-p 8080:8080 \
<docker_image_id>

Now you will be able to access the containerized application on your local machine!

License

This repo is licensed under the MIT License.

About

The RESTful web service that powers the data in my portfolio website.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published