OMDB API

This project is a personal learning project. OMDB API is a movie and series database presented as a JSON-api. The data is downloaded from OMDB which is a free community driven database for film media. The goal of the project has been to create a full featured ideomatic Go JSON API, which uses few dependencies and abstractions.

Stack:

Sentral to the design of the application is Alex Edwards’ books Let’s Go and Let’s Go Further. You can read more about the technology stack and design desitions taken in the project below.

Created by Torkel Aannestad

Jump to the API-documentation: API documentation

Quickstart

The API is open for anyone to use. Sign up and activate you user account and you are ready to use the API. The database will occationally be reset, but please don’t perform to many destructive operations.

You’ll get access with 3 steps:

  1. User signup
  2. Confirm your email with token
  3. Authenticate with email and password to get a request token

1. User Signup

  BODY='{"name": "Jake Perolta","email": "[email protected]", "password": "yourSecurePassword"}'
        curl -d "$BODY" https://omdb-api.torkelaannestad.com/v1/users

2. User Activation

An email is sent to your email with activation token. Send the following request to active your account.

  BODY='{"token": token-from-email}'
        curl -X PUT -d "$BODY" https://omdb-api.torkelaannestad.com/v1/users/activate

Reponse: a user object with updated “activated” value.

3. Get Auth Token

  BODY='{"email": "[email protected]", "password": "pa55word"}'
        curl -d "$BODY" https://omdb-api.torkelaannestad.com/v1/auth/authentication

Response:

{"authentication_token":{"token":"JZ5B4SABDN7PBKUFKROWAQM7DU","expiry":"2024-12-13T09:16:07.9290901Z"}}


Request data

  curl -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/movies/35819


Database and Model design

Mailer

Middleware

MISC

Roadmap

API Documentaion

Base URL and example endpoint:

 https://omdb-api.torkelaannestad.com/v1/healthcheck

Resources

Overview

Healthcheck

 GET /v1/healthcheck

Movies

The movies table include both movies, series and episodes. Series uses the parent_id and series_id fields to form a hierarchy between top level series, seasons and episodes.

{
        "id": 1,
        "parent_id": null,
        "series_id": null,
        "name": "Inception",
        "date": "2010-07-16T00:00:00Z",
        "kind": "movie",
        "runtime": 148,
        "budget": 160000000,
        "revenue": 829895144,
        "homepage": "https://www.inceptionmovie.com",
        "vote_average": 8.8,
        "vote_count": 210000,
        "abstract": "A skilled thief is given a chance at redemption if he can successfully perform inception.",
        "version": 1
      }
GET /v1/movies
 curl -H "Authorization: Bearer yourTokenHere" "https://omdb-api.torkelaannestad.com/v1/movies?name=dark%20knight&kind=movie&page=1&page_size=2&sort=id"

Example response:

{
        "metadata": {
          "current_page": 1,
          "page_size": 2,
          "first_page": 1,
          "last_page": 3,
          "total_records": 5
        },
        "movies": [
          {
            "id": 155,
            "parent_id": 158459,
            "series_id": null,
            "name": "The Dark Knight",
            "date": "2008-07-18T00:00:00Z",
            "kind": "movie",
            "runtime": 150,
            "budget": 185000000,
            "revenue": 970000000,
            "homepage": "",
            "vote_average": 6.9402985573,
            "vote_count": 67,
            "abstract": "",
            "version": 1
          },
          {
            "id": 32937,
            "parent_id": 158459,
            "series_id": null,
            "name": "The Dark Knight Rises",
            "date": "2012-07-20T00:00:00Z",
            "kind": "movie",
            "runtime": 164,
            "budget": 250000000,
            "revenue": 576798000,
            "homepage": "http://www.thedarkknightrises.com/",
            "vote_average": 6.125,
            "vote_count": 8,
            "abstract": "",
            "version": 1
          }
        ]
      }
POST /v1/movies
 BODY='{"name":"Go programming is awesome","date":"2024-12-02T00:00:00Z", "kind":"movie", "runtime":108,"budget":0,"revenue":0,"homepage":"", "vote_average": 5.4, "votes_count": 23, "abstract": ""}'
       curl -d "$BODY" -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/movies

Response

{
        "movie": {
          "id": 272776,
          "parent_id": {
            "Int64": 0,
            "Valid": false
          },
          "series_id": {
            "Int64": 0,
            "Valid": false
          },
          "name": "Go programming is awesome",
          "date": "2024-12-02T00:00:00Z",
          "kind": "movie",
          "runtime": 108,
          "budget": 0,
          "revenue": 0,
          "homepage": "",
          "vote_average": 5.4,
          "vote_count": 23,
          "abstract": "",
          "version": 1
        }
      }
GET /v1/movies/:id
 curl -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/movies/35819

Response: same as create movie.

PATCH /v1/movies/:id
 BODY='{ "vote_average": 5.6, "votes_count": 25}'
       curl -X PATCH -d "$BODY" -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/movies/272775
DELETE /v1/movies/:id
 curl -X DELETE -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/movies/272775

People

GET /v1/people
 curl -H "Authorization: Bearer YOUR_TOKEN" "https://omdb-api.torkelaannestad.com/v1/people?name=john&page=1&page_size=5&sort=id"
POST /v1/people
 BODY='{"name":"John Doe","birthday":"1944-05-14T00:00:00Z","gender":"0","aliases":["foo, bar"]}'
       curl -d "$BODY" -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/people
GET /v1/people/:id
 curl -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/people/311418
PATCH /v1/people/:id
 BODY='{"name":"John Doeski","gender":"99"'
       curl -X PPATCH -d "$BODY" -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/people

Response: the updated user object.

DELETE /v1/people/:id
 curl -X DELETE -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/people/311418

Casts

POST /v1/casts
 BODY='{"movie_id":35819,"person_id":287,"job_id":15,"role":"Very cool role","position":1}'
      curl -d "$BODY" -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/casts
GET /v1/casts/by-movie-id/:id
 curl -H "Authorization: Bearer yourTokenHere" "https://omdb-api.torkelaannestad.com/v1/casts/by-movie-id/35819"

Reponse: list of casts

GET /v1/casts/by-person-id/:id
 curl -H "Authorization: Bearer yourTokenHere" "https://omdb-api.torkelaannestad.com/v1/casts/by-person-id/2524"

Reponse: list of casts

PATCH /v1/casts/:id
 BODY='{"role":"Luke Skywalker","position":2}'
       curl -X PATCH -d "$BODY" -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/casts/1260480
DELETE /v1/casts/:id
 curl -X DELETE -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/casts/1260479

Jobs

POST /v1/jobs
 BODY='{"name":"Executive Producer"}'
       curl -d "$BODY" -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/jobs
GET /v1/jobs/:id
 curl -H "Authorization: Bearer yourTokenHere" "https://omdb-api.torkelaannestad.com/v1/jobs/1050"
PATCH /v1/jobs/:id
 BODY='{"name":"Super Executive Producer"}'
       curl -X PATCH -d "$BODY" -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/jobs/1050
DELETE /v1/jobs/:id
 curl -X DELETE -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/jobs/1050

Categories

POST /v1/categories
 BODY='{"name":"Family Drama"}'
       BODY='{"name":"Family Drama", "parent_id":12,"root_id":1}'
       curl -d "$BODY" -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/categories
GET /v1/categories/:id
 curl -H "Authorization: Bearer yourTokenHere" "https://omdb-api.torkelaannestad.com/v1/categories/20705"
PATCH /v1/categories/:id
 BODY='{"name":"Genre Adventure Subcategory", "parent_id":12,"root_id":1}'
       curl -X PATCH -d "$BODY" -H "Authorization: Bearer yourTokenHere" "https://omdb-api.torkelaannestad.com/v1/categories/20705"
DELETE /v1/categories/:id
 curl -X DELETE -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/categories/20705

Movie Keywords

POST /v1/movie-keywords
 BODY='{"movie_id":35819,"category_id": 10}'
       curl -d "$BODY" -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/movie-keywords
GET /v1/movie-keywords/:id
 curl -H "Authorization: Bearer yourTokenHere" "https://omdb-api.torkelaannestad.com/v1/movie-keywords/35819"
DELETE /v1/movie-keywords
 BODY='{"movie_id":35819,"category_id":10}'
       curl -X DELETE -d "$BODY" -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/movie-keywords

Movie Categories

POST /v1/movie-categories
 BODY='{"movie_id":35819,"category_id": 10}'
       curl -d "$BODY" -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/movie-categories
GET /v1/movie-categories/:id
 curl -H "Authorization: Bearer yourTokenHere" "https://omdb-api.torkelaannestad.com/v1/movie-categories/35819"
DELETE /v1/movie-categories
 BODY='{"movie_id":35819,"category_id":10}'
       curl -X DELETE -d "$BODY" -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/movie-categories
POST /v1/movie-links
 BODY='{"source":"Fight_Club","key":"wikipedia","movie_id":550,"language":"xx"}'
       curl -d "$BODY" -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/movie-links
GET /v1/movie-links/:id
 curl -H "Authorization: Bearer yourTokenHere" "https://omdb-api.torkelaannestad.com/v1/movie-links/550"
DELETE /v1/movie-links/:id
 curl -X DELETE -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/movie-links/348425
POST /v1/people-links
 BODY='{"source":"Brad_Pitt","key":"wikipedia","person_id":287,"language":"xx"}'
       curl -d "$BODY" -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/people-links
GET /v1/people-links/:id
 curl -H "Authorization: Bearer yourTokenHere" "https://omdb-api.torkelaannestad.com/v1/people-links/287"
DELETE /v1/people-links/:id
 curl -X DELETE -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/people-links/213048

Trailers

POST /v1/trailers
 BODY='{"key":"youtube-id-from-url","movie_id":35819,"language":"en","source":"youtube"}'
       curl -d "$BODY" -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/trailers
GET /v1/trailers/:id
 curl -H "Authorization: Bearer yourTokenHere" "https://omdb-api.torkelaannestad.com/v1/trailers/35819"
DELETE /v1/trailers/:id
 curl -X DELETE -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/trailers/10922

Images

POST /v1/images
 BODY='{"object_id":272775, "object_type": "Movie"}'
       curl -d "$BODY" -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/images
GET /v1/images/:id
 curl -H "Authorization: Bearer yourTokenHere" "https://omdb-api.torkelaannestad.com/v1/images/60360"
GET /v1/images
 curl -H "Authorization: Bearer yourTokenHere" "https://omdb-api.torkelaannestad.com/v1/images?object_id=272775&object_type=Movie"
PATCH /v1/images/:id
 BODY='{"object_id":272775, "object_type": "Movie"}'
       curl -X PATCH -d "$BODY" -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/images/60360
DELETE /v1/images/:id
 curl -X DELETE -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/images/60360

Users

POST /v1/users
  BODY='{"name": "Jake Perolta","email": "[email protected]", "password": "yourSecurePassword"}'
        curl -d "$BODY" https://omdb-api.torkelaannestad.com/v1/users
PUT /v1/users/activated
  BODY='{"token": token-from-email}'
        curl -X PUT -d "$BODY" https://omdb-api.torkelaannestad.com/v1/users/activate
POST /v1/users/resend-activation-token
  BODY='{"email": [email protected]}'
        curl -d "$BODY" https://omdb-api.torkelaannestad.com/v1/users/resend-activation-token

Response: json message confirmation.

Authentication

Authentication endpoint are protected with an additional rate limiter with a slow refill rate. This is to protect agains password sprays or other brute force methods agains the auth resources.

POST /v1/auth/authentication
  BODY='{"email": "[email protected]", "password": "pa55word"}'
        curl -d "$BODY" https://omdb-api.torkelaannestad.com/v1/auth/authentication

Response: auth token

POST /v1/auth/change-password
  BODY='{"current_password": "pa55word", "password": "NewStrongerpa55word"}'
        curl -d "$BODY" https://omdb-api.torkelaannestad.com/v1/auth/change-passord

Response: auth token

POST v1/auth/password-reset-verify-email
 BODY='{"email": "[email protected]"}'
       curl -d "$BODY" https://omdb-api.torkelaannestad.com/v1/auth/password-reset-verify-email

Response: json message

POST v1/auth/password-reset
  BODY='{"token": "ZAAKSYTB2CV2RU2OOQ2JA5K35Y", "new_password": "NewStrongerpa55word"}'
        curl -d "$BODY" https://omdb-api.torkelaannestad.com/v1/auth/reset-password

Response: new authentication token

POST v1/auth/revoke
  curl -X POST -H "Authorization: Bearer yourTokenHere" https://omdb-api.torkelaannestad.com/v1/auth/revoke

Response: json message confirmation

Error Handling