The stack-overflow-bridge-API is an API that consumes public data from Stack Overflow through an integration with the official Stack Exchange API. This API allows programmatic access to relevant information about questions and answers on Stack Overflow.
The project implements two main endpoints as examples:
-
List Questions: This endpoint allows you to list questions from Stack Overflow, with the ability to sort and paginate them according to specified parameters.
Endpoint:
/questions
HTTP Method: GET
Parameters:
page
: Page number for pagination (minimum 1, default 1).pageSize
: Page size for pagination (maximum 100, default 10).order
: Order of the questions (can be "asc" or "desc", default is "desc").sort
: Sorting parameter for the questions (can be "activity", "votes", "creation", "hot", "week", "month", default is "activity").
-
Get Answers: This endpoint allows you to retrieve the answers associated with a specific question on Stack Overflow.
Endpoint:
/questions/{id}/answers
HTTP Method: GET
Parameters:
id
: ID of the Stack Overflow question.
To use the stack-overflow-bridge-API, you need to configure two environment variables:
STACK_EXCHANGE_URL
: The base URL of the Stack Exchange API being integrated. By default, it is set tohttps://api.stackexchange.com/2.3
.STACK_EXCHANGE_KEY
: The access key for the Stack Exchange API. This key is provided by Stack Overflow when registering an application on Stack Apps. It is important to have this key to avoid rate limiting by Stack Exchange.
-
Clone the project from the repository.
-
Navigate to the project directory.
-
Run the following command to set up and launch the project:
make deploy
-
Once the project is successfully deployed, you can access it via your web browser by visiting http://127.0.0.1:8080.
Our project includes comprehensive tests to ensure the quality and reliability of the application. We have implemented unit tests for both the Application and Infrastructure layers, as well as WebTestCase tests for our controllers.
- Unit Tests: These are located in the
tests/Application
andtests/Infrastructure
directories. They cover the core logic and functionalities of our application and infrastructure layers. - Web Tests: These are located in the
tests/Api
directory. They utilize Symfony'sWebTestCase
to test the behavior and responses of our controllers in a simulated HTTP environment.
To execute the tests, follow these steps:
- Deploy the application: Ensure all services are up and running.
make deploy
- Run the tests: This will execute all the tests in the project.
make test
By following these commands, you can verify that all aspects of the application are working as expected.
The application architecture follows the principles of clean architecture, also known as hexagonal architecture, combined with the ports and adapters pattern. This architectural approach promotes modularity, separation of concerns, and ease of maintenance.
The application is organized into different folders, each with a specific responsibility:
-
Api: Contains the API endpoints that provide access to Stack Overflow resources.
-
Application: Contains the use cases of the application, represented by the answer information provider (
AnswerInfoProvider
) and question information provider (QuestionInfoProvider
). -
Domain: Contains the domain classes such as
Answer
,Owner
, andQuestion
, and the repository interfaces (AnswerRepositoryInterface
andQuestionRepositoryInterface
) that define contracts for data persistence. -
Infrastructure/Client: Contains the clients that integrate with Stack Exchange (
AnswerClient
andQuestionClient
). These clients implement the repository interfaces (AnswerRepositoryInterface
andQuestionRepositoryInterface
) defined in the domain. -
Infrastructure/Event: Contains the implementation of events such as
KernelExceptionEvent
, which captures exceptions and transforms them into appropriate JSON responses to improve error handling in the application.
The folder structure provides a clear separation of responsibilities and facilitates code maintenance.
The architecture reflects the principles of ports and adapters by clearly separating the core application logic from implementation details. Ports represent the interfaces through which the application interacts with the external world, while adapters are responsible for connecting the ports with concrete implementation details.
Swagger has been added to our API using the NelmioApiDocBundle library. This integration allows us to generate interactive API documentation where you can explore and test the different endpoints easily.
You can access the API documentation generated by Swagger at the following URL:
NelmioApiDocBundle makes it easy to create detailed and clear documentation for our API, thus improving the understanding and usage of the API by developers. For more information about NelmioApiDocBundle, you can refer to the official documentation.
The stack-overflow-bridge-API provides structured and programmatic access to Stack Overflow data. So far, we have implemented functionalities to paginate questions and retrieve the answers associated with those questions. Here are some possible next steps for further development of the API:
Implement a user authentication system to allow users to access additional API functionalities, such as posting questions, answering questions, voting, commenting, and more.
Allow authenticated users to create new questions and answers, edit their existing posts, and delete them if necessary. This will provide full functionality to interact with Stack Overflow through the API.
Implement the ability to comment on questions and answers, as well as vote for questions and answers. This will enable greater user interaction with the content.
Introduce advanced search functionalities that allow users to search for questions by tags, publication date, number of votes, etc. This will enhance users' ability to find relevant content.
Implement endpoints that provide statistics on API usage, question and answer popularity metrics, tag trends, etc. This will help developers better understand how the API is being used.