RESTful server application created in Java 11 with Spring Boot framework. The application communicates with GitHub REST API and allows to:
- list repositories created by given GitHub user,
- count total stars (stargazers) in all repos for specific GitHub user.
β οΈ Important! Before running the application, make sure you have configuredGITHUB_TOKEN
environment variable (either in OS or IDE), containing GitHub authorization token (withoutBearer
prefix). Application will fail to start with indeterminate variable!
- Clone this repository (
git clone https://github.com/kszapsza/allegro-intern-recruitment.git
). - Make sure you have installed Java β₯11 and Gradle (and if
JAVA_HOME
is set in OS environment variables). - Open local project directory in any terminal.
- Build the project:
./gradlew build
. - Finally, run built project:
./gradlew bootRun
. - You can also run tests with
./gradlew test
command.
- Clone this repository, either manually or from IDE itself (Get from VCS).
- Wait for symbols to index, then run Gradle build task.
- Run main application class entry point (
AllegroInternRecruitmentApplication.main()
). - You can also run tests by right-clicking test module and selecting Run.
Returns all repositories in user {username}
profile.
curl -X GET http://localhost:8080/api/v1/repos/{username}?page={page}&per_page={per_page}
Sample request:
curl -X GET http://localhost:8080/api/v1/repos/allegro?page=1&per_page=2
page
β number of page to be displayed (optional, 1st page by default)per_page
β records to be displayed per page (optional, 30 records by default)
Sample response:
repositories
β list of user repositoriesname
β repository namestargazers_count
β amount of βstarsβ in this repository
pagination
β pagination details (total pages count, links to previous/next, last/first page)
{
"repositories": [
{
"name": "akubra",
"stargazers_count": 79
},
{
"name": "allegro-api",
"stargazers_count": 132
}
],
"pagination": {
"totalPages": 43,
"prevPage": null,
"nextPage": "http://localhost:8080/api/v1/repos/allegro?per_page=2&page=2",
"lastPage": "http://localhost:8080/api/v1/repos/allegro?per_page=2&page=43",
"firstPage": null
}
}
Returns total amount of stars (stargazers) in all user ({username}
) repositories.
curl -X GET http://localhost:8080/api/v1/stargazers/{username}
Sample request:
curl -X GET http://localhost:8080/api/v1/stargazers/allegro
Sample response:
stargazers_count
β total amount of stars in all user repos
{
"stargazers_count": 13088
}
- Centralized exception handling with
@ControllerAdvice
. - Caching using Ehcache to improve performance.
- Unit tests with Mockito and Hamcrest.
- β Asynchronous API calls. For user profiles with significant amount of repos, it takes a long time to determine
total stars amount. This is because the application has to send multiple
GET
requests to GitHub API, in order to fetch all pages of paginated result. Those requests are now sent synchronously and could be sent asynchronously to improve performance. - βοΈ Integration tests. So far I only implemented unit tests based on mocks (with Mockito). Tests module could be further expanded with some integration testing of whole app. This would require redirecting calls to GitHub API to some prepared mock server, returning test data sets.