Web application that is able to share code between collaborators via API and Web interface.
Application is able to:
- create new code snippets,
- set view and time restrictions on created snippets,
- show snippet by its ID and
- show all unrestricted code snippets.
Application use embedded H2 database and no authentication.
- Java 11
- Spring Boot 2.7.1 (Spring Web MVC, Spring Data Jpa, Spring Validation, Project Lombok, H2 database, Thymeleaf template engine)
- Gradle 7.4
Navigate to the project root directory and run ./gradlew bootRun
By default, service will run on http://localhost:8889
Following endpoints will be exposed:
Methods | Urls | Action |
---|---|---|
GET | /h2 | Access to the local database (username: sa, no password) |
POST | /api/code/new | Create new code snippet |
GET | /api/code/:id | Get code snippet by it's :id |
GET | /api/code/latest | List 10 latest unrestricted code snippets |
GET | /code/new | Create new code snippet |
GET | /code/:id | Get code snippet by it's :id |
GET | /code/latest | List 10 latest unrestricted code snippets |
Example 1: POST /api/code/new
Creates new code snippet and store it in the local database under the unique UUID.
If time and views are set to zero, or negative value, code snippet don't have any limitations and can be displayed as much as desired.
First snippet:
{
"code": "public static void main(String[] args) { }",
"time": 0,
"views": 0
}
Response: 200 OK.
Response body:
{
"id": "e9229957-a76a-4c8f-b331-16fae7874044"
}
Second snippet:
{
"code": "public class CodeSnippet { }",
"time": 0,
"views": 0
}
Response: 200 OK.
Response body:
{
"id": "48bf00d3-c245-47d8-a081-0dc5d2bf44ac"
}
Third snippet:
{
"code": "public class SecretCode { }",
"time": 5000,
"views": 5
}
Response: 200 OK.
Response body:
{
"id": "360f2c38-5d78-4a6d-848f-621c83f24a9b"
}
Example 2: GET /api/code/360f2c38-5d78-4a6d-848f-621c83f24a9b
Shows code snippet by its ID number.
Response: 200 OK.
Response body:
{
"code": "public class SecretCode { }",
"date": "2023-03-13 14:48:39",
"time": 4879,
"views": 4
}
In case that some of snippet's limitation is reached (time to view or number of views), snippet will be deleted.
If same code snippet is requested after it is deleted, an error will be thrown.
Response: 404 Not Found.
Response body:
{
"time": "2023-03-13 14:52:56",
"status": 404,
"error": "Not Found",
"message": "Code snippet with requested id does not exists!",
"path": "/api/code/360f2c38-5d78-4a6d-848f-621c83f24a9b"
}
Example 3: GET /api/code/latest
Displays ten latest code snippets, ordered by date created.
Only unrestricted snippets will be shown, so only snippets whose time/views properties are set to zero (or negative value).
Response 200 OK.
Response body:
[
{
"code": "public class CodeSnippet { }",
"date": "2023-03-13 14:57:56",
"time": 0,
"views": 0
},
{
"code": "public static void main(String[] args) { }",
"date": "2023-03-13 14:57:38",
"time": 0,
"views": 0
}
]
Example 2: GET /code/12ee968b-15a4-463f-8bed-cf2303c9f84a
Example 3: GET /code/12ee968b-15a4-463f-8bed-cf2303c9f84a (time to view expired)