PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/README.md

https://bitbucket.org/ojakovlj/infobip-shorturl
Markdown | 108 lines | 67 code | 41 blank | 0 comment | 0 complexity | 014fe1c9a5611c8974e881aca11a4a07 MD5 | raw file
  1. # url-shortener
  2. Basic URL shortener built with Spring Boot with user registration and statistics tracking.
  3. ## Getting Started
  4. * To download the project, open the Git bash in the desired target folder and run
  5. ```git clone https://ojakovlj@bitbucket.org/ojakovlj/infobip-shorturl.git```
  6. * This project was created using JDK 1.8 and Maven 3.3.9 in IntelliJ IDEA.
  7. * Open your IDE of choice and import the project. Maven will download the required dependencies.
  8. * You can build the project and run the tests by running ```mvn clean package```
  9. ### How to Run
  10. Navigate to the folder where the .jar file is located and run it with ```
  11. java -jar urlshortener-1.0.jar```
  12. ## Usage instructions
  13. This section describes the requests that need to be sent to each endpoint to test the functionality.
  14. It assumes that the Spring application is running.
  15. ### To create an account
  16. Send a POST request to the ```localhost:8080/account``` endpoint. JSON data should countain the following key-value pair:
  17. ```{"accountId":"myAccountName"}```
  18. The response will contain a boolean telling whether it has succeeded or failed, a description text, and the user password.
  19. ### To register an URL to the URL shortener
  20. Send a POST request to the ```localhost:8080/register``` endpoint. There must be an Authorization Header with the following
  21. format of credentials encoded in Base64: ```username:password```
  22. The request body should be JSON data formatted as ```{"url":"MyVeryLongUrl", "redirectType": 302}```
  23. The response will contain a shortened URL if successful or the original URL if unsuccessful.
  24. ### To use the URL shortener
  25. Send a GET request to the ```localhost:8080/redirect/{ShortURL}``` endpoint. There must be an Authorization Header with the following
  26. format of credentials encoded in Base64: ```username:password```
  27. If successful, you will be redirected to the original URL.
  28. ### To view user statistics
  29. Send a GET request to the ```localhost:8080/statistic/{AccountId}``` endpoint. There must be an Authorization Header with the following
  30. format of credentials encoded in Base64: ```username:password```
  31. The response will be a hashmap containing the original URL and the number of redirects.
  32. ## Components
  33. ### ShortenerController.java
  34. The REST endpoints are located in this source file. Supported endpoints:
  35. * ```/account``` - Allows user registration by receiving an AccountId. A password is returned along
  36. with a description and success status
  37. * ```/register``` - Used to register an URL. Returns a shortened URL. Requires authentication
  38. * ```/statistics/{AccountId}``` - Allows access to user's statistics, listing all the shortened URLs and
  39. a number of redirects. Requires authentication
  40. * ```/redirect/{ShortURL}``` - Redirects the user according to the shortened URL. Requires authentication
  41. * ```/help``` - Displays this help page
  42. ### UrlShortenerApplication.java
  43. This is the main class for the Spring Boot application.
  44. ### ShortenerControllerTest.java
  45. Contains the integration tests for the ShortenerController. Six included tests cover the entire
  46. functionality of the application's endpoints. ```testCreateAccount``` and ```testCreateExistingAccount```
  47. are aimed at the /account endpoint, ```testRegisterURL``` and ```testRegisterURLWrongCredentials```
  48. are aimed at the /register endpoint, ```testUrlRedirect``` checks the redirection functionality and
  49. ```testRedirectStatistics``` checks the statistics feature.
  50. ### UserRepository.java
  51. A CRUD repository for storing User objects. Defines several methods used by the ShortenerController.
  52. ### User.java
  53. A repository entity containing information of a user's account, including the AccountId, the password and the
  54. user's registered URLs.
  55. ### ShortURL.java
  56. This class describes a URL entry submitted by a user. Contains the original full URL, the shortened
  57. URL, the number of redirects and the redirect type (301 or 302).
  58. ### ShortURLRequest.java
  59. POJO which serves as a JSON request for the /register endpoint. Contains the original URL which needs to be
  60. shortened and the desired redirect type.
  61. ### AccountResponse.java
  62. POJO created from JSON as a response for the /account endpoint. Has a boolean flag with success information,
  63. description (success or failure) and the user's password.
  64. ### ShortURLResponse.java
  65. POJO contains the shortened URL, a response from the /register endpoint.
  66. ### StatisticsResponse.java
  67. POJO created from the response of the /statistics endpoint. Has a hashmap of original URLs and a redirect counter.