Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<img src="https://raw.githubusercontent.com/hotheadhacker/no-as-a-service/main/assets/imgs/image.png" width="800" alt="No-as-a-Service Banner"/>
</p>


Ever needed a graceful way to say “no”?
This tiny API returns random, generic, creative, and sometimes hilarious rejection reasons — perfectly suited for any scenario: personal, professional, student life, dev life, or just because.

Expand All @@ -15,6 +14,7 @@ Built for humans, excuses, and humor.
## 🚀 API Usage

**Base URL**

```
https://naas.isalman.dev/no
```
Expand All @@ -23,17 +23,52 @@ https://naas.isalman.dev/no
**Rate Limit:** `10 requests per minute per IP`

### 🔄 Example Request

```http
GET /no
```

Or filter by category:

```http
GET /no?category=funny
```

### ✅ Example Response

```json
{
"reason": "This feels like something Future Me would yell at Present Me for agreeing to."
}
```

### 🗂️ Optional Query: `category`

Use the `category` query parameter to filter reasons by type.

**Available categories:**

- professional
- personal
- funny
- relationship
- direct
- grateful

Example:

```http
GET /no?category=student
```

If no reasons are found for that category:

```json
{
"error": "No reasons found for the given category."
}
```

Use it in apps, bots, landing pages, Slack integrations, rejection letters, or wherever you need a polite (or witty) no.

---
Expand All @@ -43,27 +78,32 @@ Use it in apps, bots, landing pages, Slack integrations, rejection letters, or w
Want to run it yourself? It’s lightweight and simple.

### 1. Clone this repository

```bash
git clone https://github.com/hotheadhacker/no-as-a-service.git
cd no-as-a-service
```

### 2. Install dependencies

```bash
npm install
```

### 3. Start the server

```bash
npm start
```

The API will be live at:

```
http://localhost:3000/no
```

You can also change the port using an environment variable:

```bash
PORT=5000 npm start
```
Expand Down Expand Up @@ -115,3 +155,7 @@ Created with creative stubbornness by [hotheadhacker](https://github.com/hothead
## 📄 License

MIT — do whatever, just don’t say yes when you should say no.

```

```
25 changes: 18 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const express = require('express');
const rateLimit = require('express-rate-limit');
const fs = require('fs');
const express = require("express");
const rateLimit = require("express-rate-limit");
const fs = require("fs");

const app = express();
const PORT = process.env.PORT || 3000;

// Load reasons from JSON
const reasons = JSON.parse(fs.readFileSync('./reasons.json', 'utf-8'));
const reasons = JSON.parse(fs.readFileSync("./reasons.json", "utf-8"));

// Rate limiter: 10 requests per minute per IP
// const limiter = rateLimit({
Expand All @@ -18,9 +18,20 @@ const reasons = JSON.parse(fs.readFileSync('./reasons.json', 'utf-8'));
// app.use(limiter);

// Random rejection reason endpoint
app.get('/no', (req, res) => {
const reason = reasons[Math.floor(Math.random() * reasons.length)];
res.json({ reason });
app.get("/no", (req, res) => {
const category = req.query.category;

let filtered = reasons;

if (category) filtered = reasons.filter((r) => r.category === category);

if (filtered.length == 0)
return res
.status(404)
.json({ error: "No reasons found for the given category." });

const reason = filtered[Math.floor(Math.random() * filtered.length)];
res.json({ reason: reason.reason });
});

// Start server
Expand Down
Loading