An API that serves the latest scores of fixtures of matches in a “Mock Premier League”
- Nodejs
- PostgreSQL
- Redis
- Docker
- Users can
- Sign in
- view teams
- view completed fixtures
- view pending fixtures
- search fixtures/teams
- Admin can
- Sign in
- manage teams (add, remove, edit, view)
- create fixtures (add, remove, edit, view)
To run this API locally simply follow the instructions below:
You need to have or install the following:
- Git bash
- Npm
- Postman
-
clone repo
git clone https://github.com/fegoworks/premier-league-api.git
-
navigate to api folder
-
run installation
npm install
-
create a
.env
file with this templateDB_URL='Your postgres database url' TEST_URL='Your postgres test database url' SECRET = 'Your secret phrase'
-
start app
npm run start:dev
-
you can now make requests using postman to
localhost:3000/api/v1/
To run tests simply run the following command in your git bash or command line
npm run test
Heroku: Mock-EPL-API Documentation: Mock-EPL-API-Docs
Endpoints | Functionality |
---|---|
POST /auth/create-user | Create new user account |
POST /auth/signin | Login a user |
POST /teams | Create a team |
POST /fixtures | Create a fixture |
PATCH /teams/:teamId | Edit a team |
PATCH /fixtures/:fixtureId | Edit a fixture |
PATCH /fixtures/:fixtureId/scores | Update a fixture with scores |
DELETE /fixtures/:fixtureId | Delete a specific fixture |
DELETE /teams/:teamId | Delete a specific team post |
GET /fixtures/pending | View pending fixtures |
GET /fixtures/completed | View completed fixtures |
GET /fixtures/:fixtureId | View a specific fixture |
GET /teams/:teamId | View a specific team |
Send a POST
request to /api/v1/auth/create-user
with the following JSON structure:
{
"firstName": "Sensei",
"lastName": "Saitama",
"email": "saitama@mail.com",
"password": "password",
"isAdmin": "true"
}
For admins isAdmin
is provided with true
while for users it is set to false
. POST
and PATCH
requests are restricted to only the admin accounts. User accounts can perform GET
requests.
Send a POST
request to /api/v1/auth/signin
, with the following:
{
"email": ,
"password":
}
When you signin you'll receive a Bearer token
. You'll need this token to send any request related to teams and fixtures.
Frow now on, every request described here will require you send the Bearer token
Send a POST
request to /api/v1/teams
, with the following:
{
"teamName": "Barcelona"
}
Send a GET
request to /api/v1/teams/:teamid
Send a PATCH
request to /api/v1/teams/:teamid
, with the following:
{
"teamName": "Norwich"
}
Delete a team by placing its id in the DELETE
request URL
/api/v1/teams/:teamid
.
Send a POST
request to /fixtures
, with the following:
{
"matchDate": "03/10/2020",
"homeTeam": "Crystal Palace",
"awayTeam": "Chelsea"
}
Send a PATCH
request to /api/v1/fixtures/:fixtureId
, with the following:
{
"matchDate": "03/10/2020",
"homeTeam": "Crystal Palace",
"awayTeam": "Chelsea"
}
Send a GET
request to /api/v1/fixtures/:fixtureid
Delete a fixture by placing its id in the DELETE
request URL
/fixtures/:fixtureid
.
Send a PATCH
request to /api/v1/fixtures/:fixtureId/scores
, with the following:
{
"homeTeamScore": 5,
"awayTeamScore": 2
}
Send a GET
request to /api/v1/fixtures/pending/
Send a GET
request to /api/v1/fixtures/completed
Edafe Oghenefego @realFego