A simple HTTP server built with Elixir, Plug, and Cowboy for storing humidity sensor data.
- Elixir 1.18 or later
- Erlang/OTP
- Mix (comes with Elixir)
-
Clone the repository:
git clone <repository-url> cd veggie_vision_web_server
-
Install dependencies:
mix deps.get
To run the server in development mode:
mix runThe server will start on http://localhost:4000
To run the server in production mode:
MIX_ENV=prod mix runTo run the server in interactive mode (allows you to interact with the Elixir shell):
iex -S mixEndpoint: 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
humparameter is allowed - The
humparameter must be present - Additional query parameters are not permitted
Any other endpoint returns 404 Not Found.
Run the test suite:
mix testThe 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)
lib/application.ex- Application supervisor that starts the HTTP serverlib/veggie_http_server.ex- Main HTTP server module with humidity data storage routingmix.exs- Project configuration and dependenciestest/- Test files with comprehensive endpoint testing
plug_cowboy- HTTP server framework for Elixir