The Smartrentals API allows users to perform CRUD (Create, Read, Update, Delete) operations on property listings. Authenticated users can post new properties, including base64-encoded images. All users can retrieve property listings and contact property owners for rentals. There are three public routes available without authentication: /,/registration and /search.
- Spring Boot 3.3.6
- Java SE 17(open-jdk-17)
- Spring Data JPA
- Lombok
- H2-database
- Spring security 6
- JUnit,Mockito
- Maven and VSCODE IDE with extensions and plugins
The API uses HTTP Basic stateless authentication. Only authenticated users can create, update, and delete property listings. Unauthenticated users can retrieve property listings, contact property owners, and access the public routes.
The Property entity represents a property listing with various attributes, including address, user, area, rent, type, and base64-encoded images.
- id: Unique identifier for the property.
- address: Address of the property.
- user: Reference to the user who owns the property.
- area: Area of the property in square feet.
- rent: Rent amount for the property.
- type: Type of the property (ONE_BHK,TWO_BHK,THREE_BHK,BUNGALOW,ONE_RK).
- base64EncodedImages: List of base64-encoded images of the property.
The User entity represents a user with various attributes, including first name, last name, phone, email, and a list of properties they own.
- id: Unique identifier for the user.
- firstName: First name of the user.
- lastName: Last name of the user.
- phone: Phone number of the user.
- email: Email address of the user (used as username in Spring Security).
- password: Encrypted password of the user.
- properties: List of properties owned by the user.
Endpoint: POST /registration
Description: Register a new user.
Request Body:
{
"firstName": "John",
"lastName": "Doe",
"phone": "1234567890",
"email": "johndoe@example.com",
"password": "password123"
}Response Body:
{
"message": "Registration Successful.",
"data": {
"id": 1,
"firstName": "John",
"lastName": "Doe",
"phone": "1234567890",
"email": "johndoe@example.com"
}
}Endpoint: GET /search Description: Search for properties based on criteria. Request Query Parameters:
- address (optional): Search by address.
- type (optional): Search by property type (ONE_BHK,TWO_BHK,THREE_BHK,BUNGALOW,ONE_RK).
- minRent (optional): Minimum rent amount.
- maxRent (optional): Maximum rent amount.
Response:
{
"message": "Properties Retrieved.",
"data": [
{
"id": 1,
"address": "123 Main St, Springfield",
"area": 1200,
"rent": 1500,
"type": "THREE_BHK",
"base64EncodedImages": [
"iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAIAAAD7E5cJAAAABmJLR0QA/wD/AP+gvaeT..."
]
},
{
"id": 2,
"address": "456 Elm St, Springfield",
"area": 900,
"rent": 1000,
"type": "TWO_BHK",
"base64EncodedImages": [
"iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAIAAAD7E5cJAAAABmJLR0QA/wD/AP+gvaeT..."
]
}
]
}Endpoint: GET / Response Status: 200 OK Response Body
{
"message":"Greetings!! Have look at our docs https://github.com/Shriniwas18K/properties-crud/tree/main?tab=readme-ov-file#Smartrentals-operations-api"
}URL: /property/new Method: POST Authentication: HTTP Basic Consumes: application/json Request Body:
{
"address": "456 Elm Street, Springfield, Somewhere",
"area": 950,
"rent": 1200,
"type": "TWO_BHK",
"base64EncodedImages": [
"iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAIAAAD7E5cJAAAABmJLR0QA/wD/AP+gvaeT...",
// NOTE : it is responsiblity of user to provide the base64 encoded images,
// the rest api doesnt check wheter encoding is valid, the given images are
// stored as it is.
]
}Response: Status: 201 Created Body:
{
"message": "Property Listed.",
"data": {
"id": 1,
"address": "456 Elm Street, Springfield, Somewhere",
"area": 950,
"rent": 1200,
"type": "TWO_BHK",
"base64EncodedImages": [
"iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAIAAAD7E5cJAAAABmJLR0QA/wD/AP+gvaeT..."
]
}
}URL: /property/user Method: GET Authentication: HTTP Basic Response: Status: 200 OK Body:
{
"message": "Properties retrieved.",
"count": 2,
"data": [
{
"id": 1,
"address": "456 Elm Street, Springfield, Somewhere",
"area": 950,
"rent": 1200,
"type": "TWO_BHK",
"base64EncodedImages": [
"iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAIAAAD7E5cJAAAABmJLR0QA/wD/AP+gvaeT..."
]
},
{
"id": 2,
"address": "123 Main St, Springfield",
"area": 1200,
"rent": 1500,
"type": "THREE_BHK",
"base64EncodedImages": [
"iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAIAAAD7E5cJAAAABmJLR0QA/wD/AP+gvaeT..."
]
}
]
}URL: /property/{id} Method: GET Authentication: HTTP Basic Response: Status: 200 OK or 404 Not Found Body:
{
"message": "Property Retrieved.",
"data": {
"id": 1,
"address": "456 Elm Street, Springfield, Somewhere",
"area": 950,
"rent": 1200,
"type": "TWO_BHK",
"base64EncodedImages": [
"iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAIAAAD7E5cJAAAABmJLR0QA/wD/AP+gvaeT..."
]
}
}URL: /property/{id} Method: PUT Authentication: HTTP Basic Consumes: application/json Request Body:
{
"address": "789 Oak Street, Springfield",
"area": 1000,
"rent": 1300,
"type": "TWO_BHK",
"base64EncodedImages": [
"iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAIAAAD7E5cJAAAABmJLR0QA/wD/AP+gvaeT..."
]
}Response: Status: 200 OK or 404 Not Found Body:
{
"message": "Property Updated.",
"data": {
"id": 1,
"address": "789 Oak Street, Springfield",
"area": 1000,
"rent": 1300,
"type": "TWO_BHK",
"base64EncodedImages": [
"iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAIAAAD7E5cJAAAABmJLR0QA/wD/AP+gvaeT..."
]
}
}URL: /property/{id} Method: DELETE Authentication: HTTP Basic Response: Status: 200 OK or 404 Not Found Body:
{
"message": "Property Deleted."
}Endpoint: /user/ Method: GET Authentication: HTTP Basic Response Status: 200 OK Description: Returns a greeting message. Response:
{
"message": "Greetings!! Glad to see you here"
}Endpoint: /user/profile Method: GET Authentication: HTTP Basic Response Status: 200 OK Description: Retrieves the profile information of the authenticated user. Response:
{
"message": "User retrieved.",
"data": {
"id": 1,
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@example.com",
"phone": "1234567890",
"password": "encoded_password",
"properties": []
}
}Endpoint: /user/update Method: PUT Authentication: HTTP Basic Response Status: 202 Accepted Description: Updates the authenticated user's profile. Request Body:
{
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@example.com",
"password": "new_password",
"phone": "1234567890"
}Response
{
"message": "User details updated.",
"data": {
"id": 1,
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@example.com",
"phone": "1234567890",
"password": "encoded_password",
"properties": []
}
}Endpoint: /user/delete Method: DELETE Authentication: HTTP Basic Response Status: 202 Accepted Description: Deletes the authenticated user account and associated properties. Response:
{
"message": "User and associated properties removed."
}