initial
This commit is contained in:
commit
7640f045f1
6 changed files with 448 additions and 0 deletions
120
README.md
Normal file
120
README.md
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
# No as a Service (NaaS)
|
||||
|
||||
A simple Sinatra-based web service that provides creative "no" responses in both HTML and JSON formats.
|
||||
|
||||
## Features
|
||||
|
||||
- **Dual Format Support**: Serves both HTML (for browsers) and JSON (for APIs)
|
||||
- **Random Responses**: Returns a random "no" response from a curated list
|
||||
- **Modern Styling**: Beautiful glassmorphism design for the HTML interface
|
||||
- **Health Checks**: Built-in health check endpoint for monitoring
|
||||
- **Containerized**: Ready for deployment with Podman/Docker
|
||||
|
||||
## API Endpoints
|
||||
|
||||
- `GET /` - Returns a random "no" (HTML by default, JSON with Accept header)
|
||||
- `GET /api/no` - Explicit JSON endpoint with additional metadata
|
||||
- `GET /health` - Health check endpoint
|
||||
- `GET /*` - Catch-all that returns "no" for any other path
|
||||
|
||||
## Content Negotiation
|
||||
|
||||
The root endpoint (`/`) supports content negotiation:
|
||||
- Browser requests get HTML
|
||||
- Requests with `Accept: application/json` get JSON
|
||||
|
||||
## Usage Examples
|
||||
|
||||
### HTML (Browser)
|
||||
```
|
||||
curl http://localhost:4567/
|
||||
```
|
||||
|
||||
### JSON
|
||||
```bash
|
||||
# Using Accept header
|
||||
curl -H "Accept: application/json" http://localhost:4567/
|
||||
|
||||
# Using explicit API endpoint
|
||||
curl http://localhost:4567/api/no
|
||||
```
|
||||
|
||||
### Sample JSON Response
|
||||
```json
|
||||
{
|
||||
"answer": "Absolutely not",
|
||||
"timestamp": "2025-06-06T12:00:00Z",
|
||||
"service": "No as a Service",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
```
|
||||
|
||||
## Local Development
|
||||
|
||||
### Prerequisites
|
||||
- Ruby 3.2+
|
||||
- Bundler
|
||||
|
||||
### Setup
|
||||
```bash
|
||||
# Install dependencies
|
||||
bundle install
|
||||
|
||||
# Run the application
|
||||
ruby app.rb
|
||||
|
||||
# Or use rerun for auto-reload during development
|
||||
bundle exec rerun ruby app.rb
|
||||
```
|
||||
|
||||
The application will be available at `http://localhost:4567`
|
||||
|
||||
## Container Deployment
|
||||
|
||||
### Build with Podman
|
||||
```bash
|
||||
podman build -t naas .
|
||||
```
|
||||
|
||||
### Run with Podman
|
||||
```bash
|
||||
# Basic run
|
||||
podman run -p 4567:4567 naas
|
||||
|
||||
# Run in background with restart policy
|
||||
podman run -d --name naas-service -p 4567:4567 --restart=always naas
|
||||
|
||||
# Run with custom port
|
||||
podman run -p 8080:4567 -e PORT=4567 naas
|
||||
```
|
||||
|
||||
### Docker Commands
|
||||
The same commands work with Docker by replacing `podman` with `docker`.
|
||||
|
||||
## Environment Variables
|
||||
|
||||
- `PORT` - Port to bind to (default: 4567)
|
||||
|
||||
## Health Monitoring
|
||||
|
||||
The service includes a health check endpoint at `/health` that returns:
|
||||
```json
|
||||
{
|
||||
"status": "healthy",
|
||||
"timestamp": "2025-06-06T12:00:00Z"
|
||||
}
|
||||
```
|
||||
|
||||
## File Structure
|
||||
|
||||
```
|
||||
.
|
||||
├── app.rb # Main Sinatra application
|
||||
├── Gemfile # Ruby dependencies
|
||||
├── Containerfile # Container build instructions
|
||||
└── README.md # This file
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
This project is released under the MIT License. Feel free to use it for your negative response needs!
|
||||
Loading…
Add table
Add a link
Reference in a new issue