From 11d1cbbb28f2fa161e9636608ba1a817ffe1b791 Mon Sep 17 00:00:00 2001 From: Damjan Pavlica Date: Sun, 24 Nov 2024 19:32:44 +0100 Subject: [PATCH] move to /api --- README.md | 20 ++++++++++---------- src/app.js | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4598fa2..2a8d43f 100644 --- a/README.md +++ b/README.md @@ -12,18 +12,18 @@ Feel free to get involved, suggest or implement new features. ### Public Routes -#### GET [`/quotes/random`](/quotes/random) +#### GET [`/api/quotes/random`](/api/quotes/random) - **Description**: Fetches a random programming quote. -#### GET [`/quotes?author=Edsger_W._Dijkstra`](/quotes?author=Edsger_W._Dijkstra) -#### GET [`/quotes?page=1"esPerPage=20`](/quotes?page=1"esPerPage=20) -#### GET [`/quotes`](/quotes) +#### GET [`/api/quotes?author=Edsger_W._Dijkstra`](/api/quotes?author=Edsger_W._Dijkstra) +#### GET [`/api/quotes?page=1"esPerPage=20`](/api/quotes?page=1"esPerPage=20) +#### GET [`/api/quotes`](/api/quotes) - **Description**: Retrieves quotes, with optional query parameters: - `page`: The page number (default: 1). - `quotesPerPage`: Number of quotes per page (default: 20). - `author`: Filter quotes by a specific author. -#### GET `/quotes/:id` +#### GET `/api/quotes/:id` - **Description**: Retrieves a single quote by its unique ID. --- @@ -32,7 +32,7 @@ Feel free to get involved, suggest or implement new features. Access to these routes requires a valid token. -#### POST `/quotes` +#### POST `/api/quotes` - **Description**: Adds a new quote. - **Required Parameters** (in JSON body): - `author`: The name of the author (should match a Wikipedia entry). @@ -40,25 +40,25 @@ Access to these routes requires a valid token. - **Optional Parameters**: - `source`: The source or context of the quote. -#### PUT `/quotes/:id` +#### PUT `/api/quotes/:id` - **Description**: Updates an existing quote by ID. - **Parameters** (in JSON body): - `author`, `text`, or `source`. -#### POST `/quotes/vote` +#### POST `/api/quotes/vote` - **Description**: Votes for a specific quote. - **Required Parameters** (in JSON body): - `quoteId`: The ID of the quote. - `newVote`: A numeric value (1–5). -#### DELETE `/quotes/:id` +#### DELETE `/api/quotes/:id` - **Description**: Deletes a quote by its unique ID. --- ### Authentication -#### GET `/auth/token` +#### GET `/api/auth/token` - **Description**: Logs in or registers a new user. - **Required Parameters** (in JSON body): - `email`: The user's email address. diff --git a/src/app.js b/src/app.js index 585011c..98ac886 100644 --- a/src/app.js +++ b/src/app.js @@ -7,7 +7,7 @@ import mongoose from 'mongoose' import { marked } from 'marked' import { port, domain } from './config/host.js' -import router from './routes/router.js' +import apiRouter from './routes/router.js' import { normalizeJsonKeys } from './middleware/normalize.js' const app = express() @@ -31,7 +31,7 @@ app.get('/', async(req, res) => { } }) -app.use('/', router) +app.use('/api/', apiRouter) // SERVER app.listen(port, () => console.log(`Serving on ${domain}`))