BlogPass is an API designed around a blog theme, which processes new post data from an external resource and tracks the Progress Status for the UOL Compass Challenge 3.
BlogPass is a RESTful API that handles post data operations using HTTP verbs (GET, POST, PUT, DELETE) by consuming data with OpenFeign. Additionally, it employs a message broker to handle multiple requests and processes them accordingly. While managing the posts, the Progress Status is updated and recorded in the history.
As an added feature, it allows the registration of new users who can access the content provided by BlogPass.
The following technologies were utilized in this project:
External data resource from:
To test this project in your computer, you should have the following tools installed:
- Git Bash, to clone this project
- An IDE (like IntelliJ or Eclipse) to run the Spring Java code
- An software testing tools (like Postman or Insomnia)
Follow these steps:
- Clone this repository in Git Bash using the following command:
git clone https://github.com/mandis-ncs/blog_pass.git
- Open the cloned directory in your IDE and locate the main class called 'BlogPassApplication'. Click the 'Run' icon to execute the code.
- Open your testing API software and try out the HTTP operations.
The clone will redirect you to the main branch, where basic security is enabled. If you want to test the version
- In Git Bash copy and paste to switch to another branch:
git checkout -b without_security origin/without_security
- Verify if the message "Switch to new branch without_security" appears. You are done :)
Here are the commands to use in your testing software (preferably Postman). Please follow these steps in order:
(Obs: For each request, log in using Basic Auth as either an admin or an user, unless you have changed to whithout_security branch.)
- BASIC AUTH -> In your testing software, go to the Authorization tab and select the "Basic Auth" type. Use the pre-registered admin credentials:
Username: admin
Password: admin123
(Note: You have to put the credentials in every Endpoint, to identify yourself)
- โ POST -> To process a new post, use an ID between 1 and 100 in place of {postId}:
http://localhost:8080/posts/{postId}
As example:
http://localhost:8080/posts/1
This will set the Progress Status to ENABLE if successful or FAILED if there's an issue.
- โ GET ALL -> Retrieve all registered posts, associated comments, and their Progress Status History using:
http://localhost:8080/posts
(Note: You can also log in with user credentials. More below.)
- โ PUT -> Reprocess a post using:
http://localhost:8080/posts/{postId}
- โ DELETE -> Delete a post using the same command as before. The post's status will be set to DISABLE.
http://localhost:8080/posts/{postId}
As mentioned, you can register and log in with your own credentials. By default, the application provides the following user:
Username: user
Password: user123
- ๐ REGISTER USER -> To register a new user, send a POST request to:
http://localhost:8080/blog-pass/auth/register
You have to provide a JSON body in the following format:
{
"username" : "newUser",
"password" : "newUser123"
}
Note that user credentials can only access the GET ALL method to view registered posts.
(Obs: As is used a embedded database with drop-create configuration, the newUser created will be erased when the application stop to running.)
- ๐ LOGIN -> In the Authorization tab, use your new credentials. You can also test whether your credentials are valid by sending a POST request with the JSON body mentioned above to:
http://localhost:8080/blog-pass/auth/login
If you send a bad request or search by an ID that doesn't exist, it is provided some advice to prevent errors. For example, if you try the following POST URI, the error message "The post id should be between 0 and 100." will appear.
http://localhost:8080/posts/10123
It was fascinating to apply new technologies that I wasn't previously accustomed to, such as:
- Using ActiveMQ Artemis embedded message broker to create queues automatically for receiving requests
- Utilizing OpenFeign Client to consume data from an external resource
- Employing ENUMS to save the Progress Status during post processing, allowing for time-based comparisons of my API's velocity and capacity
- Implementing basic security measures with Spring Security
Simple tests using JUnit and Mockito were performed to ensure that exceptions are thrown in error cases in the 'Service' class.
- To run these tests, navigate to the 'PostServiceImplTest' class in your repository and click the run button.
(Note: the test is placed in "src/test")
The documentation was made automatically using Swagger. To konw more about BlogPass API, you can access it by copying the following URL in your browser:
[localh](http://localhost:8080/swagger-ui.html)
(Note: You can only access it when the project is running)