A RESTful web service built with Spring Boot that generates customizable random number sequences. Includes a Python client demonstrating cross-language service consumption.
- RESTful API for random number generation
- Configurable parameters (size, range, origin)
- Built with Spring Boot and Gradle
- Python client implementation
- Automatic JSON response formatting
- Backend: Java 11, Spring Boot 2.x
- Build System: Gradle
- API Testing: Python requests library
- Server: Embedded Tomcat
- IDE: VS Code with Spring Boot extensions
- Model (
Rand.java
)
public class Rand {
private int[] numArray;
public Rand(long size, int origin, int bound) {
Random random = new Random();
size = size < 1001 ? size : 1000;
numArray = random.ints(size, origin, bound).toArray();
}
}
- Controller
- Handles HTTP GET requests
- Parameter validation
- Response formatting
- Python Client
- Service consumption example
- Error handling
- Response processing
GET /random?bound={bound}&origin={origin}&size={size}
Parameter | Type | Description |
---|---|---|
bound |
int |
Upper bound (exclusive) |
origin |
int |
Lower bound (inclusive) |
size |
int |
Number of random values |
{
"numArray": [3, 1, 4, 1, 5]
}
- Java 11+
- Python 3.x (for client)
- Gradle
- Clone repository:
git clone https://github.com/yourusername/random-numbers-service.git
cd random-numbers-service
- Build project:
cd SpringWebService/rand
./gradlew build
- Run server:
./gradlew bootRun
- Install Python requirements:
pip install requests
- Run client:
cd consumer
python rand.py
.
├── SpringWebService/ # Java Spring Boot service
│ └── rand/
│ ├── src/
│ │ ├── main/
│ │ │ ├── java/
│ │ │ └── resources/
│ │ └── test/
│ └── build.gradle
├── consumer/ # Python client
│ └── rand.py
└── demo/ # Screenshots
Run Spring Boot tests:
./gradlew test
Test Python client:
python -m pytest consumer/test_rand.py
Random Numbers JSON Response | Random Numbers Raw Data |
![]() |
![]() |
Spring Boot Server Running | Python Client Consumption |
![]() |
![]() |
- Fork repository
- Create feature branch (
git checkout -b feature/AmazingFeature
) - Commit changes (
git commit -m 'Add AmazingFeature'
) - Push to branch (
git push origin feature/AmazingFeature
) - Open Pull Request
Distributed under the MIT License. See LICENSE
for more information.
- Spring Boot Documentation
- Python Requests Library
- RESTful API Best Practices