Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nabilshadman/spring-boot-random-numbers-restful-web-service
A RESTful web service (created with Spring Boot) that returns a list of random numbers to the consumer
https://github.com/nabilshadman/spring-boot-random-numbers-restful-web-service
backend java java-development rest-api rest-apis software-engineering spring-boot web-service
Last synced: 26 days ago
JSON representation
A RESTful web service (created with Spring Boot) that returns a list of random numbers to the consumer
- Host: GitHub
- URL: https://github.com/nabilshadman/spring-boot-random-numbers-restful-web-service
- Owner: nabilshadman
- License: mit
- Created: 2021-06-05T06:25:19.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-12-04T14:37:50.000Z (about 1 month ago)
- Last Synced: 2024-12-04T15:33:40.874Z (about 1 month ago)
- Topics: backend, java, java-development, rest-api, rest-apis, software-engineering, spring-boot, web-service
- Language: Java
- Homepage:
- Size: 528 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ฒ Spring Boot Random Numbers Service
A RESTful web service built with Spring Boot that generates customizable random number sequences. Includes a Python client demonstrating cross-language service consumption.
## ๐ Features
- RESTful API for random number generation
- Configurable parameters (size, range, origin)
- Built with Spring Boot and Gradle
- Python client implementation
- Automatic JSON response formatting## ๐ ๏ธ Technical Stack
- **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## ๐๏ธ Architecture
### Core Components
1. **Model (`Rand.java`)**
```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();
}
}
```2. **Controller**
- Handles HTTP GET requests
- Parameter validation
- Response formatting3. **Python Client**
- Service consumption example
- Error handling
- Response processing## ๐ API Reference
### Get Random Numbers
```http
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 |#### Response Example
```json
{
"numArray": [3, 1, 4, 1, 5]
}
```## ๐ฆ Getting Started
### Prerequisites
- Java 11+
- Python 3.x (for client)
- Gradle### Server Setup
1. Clone repository:
```bash
git clone https://github.com/yourusername/random-numbers-service.git
cd random-numbers-service
```2. Build project:
```bash
cd SpringWebService/rand
./gradlew build
```3. Run server:
```bash
./gradlew bootRun
```### Client Usage
1. Install Python requirements:
```bash
pip install requests
```2. Run client:
```bash
cd consumer
python rand.py
```## ๐๏ธ Project Structure
```
.
โโโ SpringWebService/ # Java Spring Boot service
โ โโโ rand/
โ โโโ src/
โ โ โโโ main/
โ โ โ โโโ java/
โ โ โ โโโ resources/
โ โ โโโ test/
โ โโโ build.gradle
โโโ consumer/ # Python client
โ โโโ rand.py
โโโ demo/ # Screenshots
```## ๐งช Testing
Run Spring Boot tests:
```bash
./gradlew test
```Test Python client:
```bash
python -m pytest consumer/test_rand.py
```## ๐ธ Screenshots
Random Numbers JSON Response
Random Numbers Raw Data
Spring Boot Server Running
Python Client Consumption
## ๐ค Contributing
1. Fork repository
2. Create feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit changes (`git commit -m 'Add AmazingFeature'`)
4. Push to branch (`git push origin feature/AmazingFeature`)
5. Open Pull Request## ๐ License
Distributed under the MIT License. See `LICENSE` for more information.
## ๐ Acknowledgments
- Spring Boot Documentation
- Python Requests Library
- RESTful API Best Practices