Skip to content

ricountzero/veggie_vision_web_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

    git clone <repository-url>
    cd veggie_vision_web_server
  2. Install dependencies:

    mix deps.get

Running the Server

Development Mode

To run the server in development mode:

mix run

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

Production Mode

To run the server in production mode:

MIX_ENV=prod mix run

Interactive Mode

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

iex -S mix

API Endpoints

Store Humidity Data

Endpoint: GET /store

Query Parameters:

  • hum (required): Humidity value to store

Examples:

# 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:

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

About

A simple HTTP server for storing humidity sensor data.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages