Skip to content

PHP Twitch API using Laravel + unitary & integration tests

Notifications You must be signed in to change notification settings

sayechu/laravel-twitch-api

Repository files navigation

Laravel Logo

Twitch API

This project is a Twitch API developed in PHP using the Laravel framework and Docker for containerization. It adheres to Clean Code principles, includes comprehensive testing, and incorporates regular code refactoring to maintain high code quality. The API provides the following endpoints:

/streamers:id (GET): Retrieves data for a given Twitch streamer by id.

 curl -X GET 'http://localhost/analytics/streamers?id=459331509'

/streams (GET): Obtains live Twitch streams.

 curl -X GET 'http://localhost/analytics/streams'

/topsofthetops:since (GET): Retrieves data for the top 40 videos of each of the top three most popular games, with an optional integer parameter since to filter results based on time (seconds).

 curl -X GET 'http://localhost/analytics/topsofthetops'
 curl -X GET 'http://localhost/analytics/topsofthetops?since=150'

/timeline:username (GET): Retrieves the list of recent streams from followed streamers.

 curl -X GET 'http://localhost/analytics/timeline?username=user_name'

/follow (POST): Allows registered users to follow a streamer.

 curl -X POST 'http://localhost/analytics/follow' \
 -H "Content-Type: application/json" \
 -d '{"username": "user_name", "streamerId": "streamer_id"}'

/unfollow (DELETE): Allows registered users to unfollow a streamer.

 curl -X DELETE 'http://localhost/analytics/unfollow' \
 -H "Content-Type: application/json" \
 -d '{"username": "user_name", "streamerId": "streamer_id"}'

/users (POST): Creates a new user with a specified username.

 curl -X POST 'http://localhost/analytics/users' \
 -H "Content-Type: application/json" \
 -d '{"username": "user_name", "password": "password"}'

/users (GET): Retrieves a list of all registered users, including the streamers each user follows.

 curl -X GET 'http://localhost/analytics/users'

How to run the project?

1. Clone Repository:

  git clone git@github.com:sayechu/laravel-twitch-api.git

2. Move to directory and composer install:

  cd laravel-twitch-api
  composer install

3. Copy environment variables file:

  cp .env.example .env

4. Run sail

Note I: alias sail='sh $([ -f sail ] && echo sail || echo vendor/bin/sail)'
Note II: run Docker Desktop before executing this command

  sail up -d

5. Run migrations

  sail php artisan migrate

  • To stop the running containers, execute:
  sail down
  • To run the unitary and integrations tests:
  ./vendor/bin/phpunit
  • To rollback the migrations:
  sail php artisan migrate:rollback