Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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 formatting

3. **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