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

https://github.com/ricountzero/veggie_vision_web_server

A simple HTTP server for storing humidity sensor data.
https://github.com/ricountzero/veggie_vision_web_server

elixir erlang-otp postgresql

Last synced: about 1 month ago
JSON representation

A simple HTTP server for storing humidity sensor data.

Awesome Lists containing this project

README

          

# Veggie Vision HTTP Server

A simple HTTP server built with Elixir, Plug, and Cowboy for storing humidity sensor data.

## Prerequisites

- Elixir 1.18 or later
- Erlang/OTP
- Mix (comes with Elixir)

## Installation

1. Clone the repository:
```bash
git clone
cd veggie_vision_web_server
```

2. Install dependencies:
```bash
mix deps.get
```

## Running the Server

### Development Mode

To run the server in development mode:

```bash
mix run
```

The server will start on `http://localhost:4000`

### Production Mode

To run the server in production mode:

```bash
MIX_ENV=prod mix run
```

### Interactive Mode

To run the server in interactive mode (allows you to interact with the Elixir shell):

```bash
iex -S mix
```

## API Endpoints

### Store Humidity Data

**Endpoint:** `GET /store`

**Query Parameters:**
- `hum` (required): Humidity value to store

**Examples:**
```bash
# Store humidity value of 75.5
curl "http://localhost:4000/store?hum=75.5"

# Store humidity value of 80
curl "http://localhost:4000/store?hum=80"
```

**Response:**
- **200 OK**: `:ok` - Humidity value stored successfully
- **400 Bad Request**: `Missing 'hum' parameter` - When hum parameter is missing
- **400 Bad Request**: `Only 'hum' parameter is allowed` - When additional parameters are provided

**Rules:**
- Only the `hum` parameter is allowed
- The `hum` parameter must be present
- Additional query parameters are not permitted

### Other Endpoints

Any other endpoint returns **404 Not Found**.

## Testing

Run the test suite:

```bash
mix test
```

The test suite includes comprehensive tests for:
- Valid humidity data storage
- Missing parameter handling
- Multiple parameter validation
- URL encoding scenarios
- Various data types (integers, floats, special characters)

## Project Structure

- `lib/application.ex` - Application supervisor that starts the HTTP server
- `lib/veggie_http_server.ex` - Main HTTP server module with humidity data storage routing
- `mix.exs` - Project configuration and dependencies
- `test/` - Test files with comprehensive endpoint testing

## Dependencies

- `plug_cowboy` - HTTP server framework for Elixir