REST API for the TwitterClone
INSERT INTO roles(name) VALUES('ROLE_ADMIN');
INSERT INTO roles(name) VALUES('ROLE_MODERATOR');
INSERT INTO roles(name) VALUES('ROLE_USER');
Below are the REST APIs for the example app.
POST /api/signup
curl --location --request POST 'http://localhost:5000/api/auth/signup' \
--header 'Content-Type: application/json' \
--data-raw '{
"username":"l00pinfinity",
"email":"[email protected]",
"password":"qwerty6"
}'
{
"success": true,
"message": "User registered successfully"
}
- Email already in use
{
"timestamp": "2023-01-18T09:22:19.190+00:00",
"status": 400,
"error": "Bad Request",
"trace": "com.boitdroid.birdapp.exception.BadRequestException: It appears that the username you entered is already taken\r\n\tat com.boitdroid.birdapp.service.UserServiceImpl.addUser(UserServiceImpl.java:42)\r\n\tat com.boitdroid.birdapp.controller.AuthController.registerUser(AuthController.java:52)\r\n\tat java.base/jdk.internal.reflect",
"message": "It appears that the email you entered is already in use",
"path": "/api/auth/signup"
}
- Username is already taken
{
"timestamp": "2023-01-18T09:22:19.190+00:00",
"status": 400,
"error": "Bad Request",
"trace": "com.boitdroid.birdapp.exception.BadRequestException: It appears that the username you entered is already taken\r\n\tat com.boitdroid.birdapp.service.UserServiceImpl.addUser(UserServiceImpl.java:42)\r\n\tat com.boitdroid.birdapp.controller.AuthController.registerUser(AuthController.java:52)\r\n\tat java.base/jdk.internal.reflect",
"message": "It appears that the username you entered is already taken",
"path": "/api/auth/signup"
}
POST /api/signin
curl --location --request POST 'http://localhost:5000/api/auth/signin' \
--header 'Content-Type: application/json' \
--data-raw '{
"usernameOrEmail":"l00pinfinity",
"password":"qwerty6"
}'
{
"accessToken": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwiaWF0IjoxNjc0MDMzODU0LCJleHAiOjE2NzQwMzc0NTR9.wyeppy7ZP5rANC0FxGDG9WopmfWFhy8xzt2wqiIOoVEJFlhU4nDr7Qabswoi845mNvRhIVFaBxm1y12d1Id0Nw",
"tokenType": "Bearer"
}
POST /api/auth/[email protected]
curl --location --request POST 'http://localhost:8080/api/auth/[email protected]' \--data-raw ''
Reset token is sent to the user via provided email if it exists.
{
"success": true,
"message": "We have sent a password reset token to [email protected]"
}
- No account with the Email Address
{
"success": false,
"message": "There is no account with an email address"
}
POST /api/auth/reset?token=2FHKJW
curl --location --request POST 'http://localhost:8080/api/reset?token=2FHKJW' \--header 'Content-Type: application/json' \--data-raw '{"password":"qwerty"}'
{
"success": true,
"message": "Your password has been successfully reset."
}
- Invalid token
{
"success": false,
"message": "The password reset link is invalid."
}
POST /api/users/in/{username}
curl --location --request GET 'http://localhost:5000/api/users/l00pinfinity'
{
"id": 1,
"username": "l00pinfinity",
"joinedAt": "2023-01-18T09:21:32Z",
"email": "[email protected]",
"tweetCount": 0
}
- No user with username provided
{
"timestamp": "2023-01-18T09:25:59.689+00:00",
"status": 404,
"error": "Not Found",
"trace": "com.boitdroid.birdapp.exception.ResourceNotFoundException: User with username: l00pinfinitys is not found\r\n\tat com.boitdroid.birdapp.repository",
"message": "User with username: l00pinfinitys is not found",
"path": "/api/users/l00pinfinitys"
}