From e6ae133449fa855f8290cd2ce9cc14a7fec91c7c Mon Sep 17 00:00:00 2001 From: sjdonado Date: Fri, 7 Feb 2025 17:22:41 +0100 Subject: [PATCH] chore: separate API reference from README --- .gitignore | 1 - docs/API.md | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 docs/API.md diff --git a/.gitignore b/.gitignore index 4dcf1be..2a072c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -/docs/ /lib/ /bin/ /.shards/ diff --git a/docs/API.md b/docs/API.md new file mode 100644 index 0000000..01db08b --- /dev/null +++ b/docs/API.md @@ -0,0 +1,152 @@ +# API Reference + +1. **Ping the API** + + - Endpoint: `GET /api/ping` + - Payload: None + - Response Example + ```json + { + "message": "pong" + } + ``` + +2. **Redirect by Slug** + + - Endpoint: `GET /:slug` + - Headers: `X-Api-Key` + - Payload: None + - Response Example + ```json + { + "data": { + "id": "84f0c7a4-8c4e-4665-b676-cb9c5e40f1db", + "refer": "http://localhost:4000/3wP4BQ", + "origin": "https://monocuco.donado.co", + "clicks": [ + { + "id": "730e2202-58f9-478c-a24c-f1c561df6716", + "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:127.0) Gecko/20100101 Firefox/127.0", + "language": "en-US", + "browser": "Firefox", + "os": "Mac OS X", + "source": "Unknown", + "created_at": "2024-07-12T19:25:22Z" + } + ] + } + } + ``` + +3. **List All Links** + + - Endpoint: `GET /api/links` + - Headers: `X-Api-Key` + - Payload: None + - Response Example + ```json + { + "data": [ + { + "id": "84f0c7a4-8c4e-4665-b676-cb9c5e40f1db", + "refer": "http://localhost:4000/3wP4BQ", + "origin": "https://monocuco.donado.co", + "clicks": [ + { + "id": "730e2202-58f9-478c-a24c-f1c561df6716", + "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:127.0) Gecko/20100101 Firefox/127.0", + "language": "en-US", + "browser": "Firefox", + "os": "Mac OS X", + "source": "Unknown", + "created_at": "2024-07-12T19:25:22Z" + } + ] + } + ] + } + ``` + +4. **List link by ID** + + - Endpoint: `GET /api/links/:id` + - Headers: `X-Api-Key` + - Payload: None + - Response Example + ```json + { + "data": { + "id": "84f0c7a4-8c4e-4665-b676-cb9c5e40f1db", + "refer": "http://localhost:4000/3wP4BQ", + "origin": "https://monocuco.donado.co", + "clicks": [ + { + "id": "730e2202-58f9-478c-a24c-f1c561df6716", + "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:127.0) Gecko/20100101 Firefox/127.0", + "language": "en-US", + "browser": "Firefox", + "os": "Mac OS X", + "source": "Unknown", + "created_at": "2024-07-12T19:25:22Z" + } + ] + } + } + ``` + +5. **Create new link** + + - Endpoint\*\*: `POST /api/links` + - Payload: + ```json + { + "url": "https://example.com" + } + ``` + - Headers: `X-Api-Key` + - Response Example: + ```json + { + "data": { + "id": "84f0c7a4-8c4e-4665-b676-cb9c5e40f1db", + "refer": "http://localhost:4000/3wP4BQ", + "origin": "https://monocuco.donado.co/test", + "clicks": [] + } + } + ``` + +6. **Update an existing link by ID** + + - Endpoint: `PUT /api/links/:id` + - Payload: + ```json + { + "url": "https://newexample.com" + } + ``` + - Headers: `X-Api-Key` + - Response Example: + ```json + { + "data": { + "id": "84f0c7a4-8c4e-4665-b676-cb9c5e40f1db", + "refer": "http://localhost:4000/3wP4BQ", + "origin": "https://newexample.com", + "clicks": [] + } + } + ``` + +7. **Delete a link by ID** + + - Endpoint: `DELETE /api/links/:id` + - Payload: None + - Headers: `X-Api-Key` + - Response Example: + ```json + { + "message": "Link deleted" + } + ``` +