Skip to content

FonsecaGoncalo/Brewery-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Brewery-API 🍺

Build Status

Brewery-API uses BreweryDB to obtain information about breweries. It allows to:

  • Get a Single Brewery by id
  • List Breweries
  • Search Breweries

You can check the Swagger for more information about each endpoint.

Brewery-API uses the OAuth 2.0 protocol (client credentials grant) for authentication and authorization. It's using okta as the authorization server.

The application is deployed using AWS Elastic Beanstalk under the domain https://brewery.gfonseca.io.

Tests

  • Units tests
  • Functional tests with Wiremock

Running Local

Prerequisites

  • Java 11
  • Maven
  • Docker

Build Jar

mvn clean intall

Build Docker Image

docker build . -t brewery-api

Run Application

docker run -p 8080:80 \
  -e CLIENT_ID=<CLIENT_ID> \
  -e CLIENT_SECRET=<CLIENT_SECRET> \
  brewery-api

Authentication

To get an access token you need to make a request to the authorization server:

POST /oauth2/default/v1/token HTTP/1.1
Host: dev-8089486.okta.com
Accept: application/json
Content-Type: application/x-www-form-urlencoded
Authorization: Basic base64(<CLIENT_ID>:<CLIENT_SECRET>)

grant_type=client_credentials&scope=read

The authorization server will respond with the following payload:

{
    "token_type": "Bearer",
    "expires_in": 600,
    "access_token": <TOKEN>,
    "scope": "read"
}

Then you need to add an Authorization header with token to all requests to the Brewery-API

GET /breweries/530 HTTP/1.1
Host: brewery.gfonseca.io
Authorization: Bearer <TOKEN>

Postman

To more easily test the api you can import the postman collection into postman and define the variables {{client_id}} and {{client_secret}}. This collection, after the Get Token request automatically adds the token to the other requests.

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published