mirror of
https://github.com/Wolvan/poll.horse.git
synced 2024-11-24 05:38:00 +01:00
cfa150cc42
The API has been moved to a /api path to distinguish it from the form submission path and make it clear it is a callable API. The API also has been rudimentarily documented.
2.6 KiB
2.6 KiB
API
API URL
The base URL for all API calls is /_backend/api.
Get poll information
Fetch JSON data of a single poll defined by the poll ID string.
-
URL
/poll/:id
-
Method:
GET
-
URL Params
Required:
id=[alphanumeric]
-
Data Params
None
-
Success Response:
- Code: 200
Content:{ "id": "abcd1234", "title": "An API requested Poll", "dupeCheckMode": "ip", "multiSelect": true, "creationTime": "2022-01-12T19:26:37.262Z", "options": [ "Option A", "Option B", "Option C" ] }
- Code: 200
-
Error Response:
- Code: 404 NOT FOUND
Content:{ "error" : "Poll not found" }
OR
- Code: 500 INTERNAL SERVER ERROR
Content:{ "error" : "<ERROR_MESSAGE_STRING>" }
- Code: 404 NOT FOUND
Get poll result
Fetch JSON data of the result of a single poll defined by the poll ID string.
-
URL
/poll-result/:id
-
Method:
GET
-
URL Params
Required:
id=[alphanumeric]
-
Data Params
None
-
Success Response:
- Code: 200
Content:{ "title": "An API requested Poll", "options": { "Option A": 0, "Option B": 3, "Option C": 1 } }
- Code: 200
-
Error Response:
- Code: 404 NOT FOUND
Content:{ "error" : "Poll not found" }
OR
- Code: 500 INTERNAL SERVER ERROR
Content:{ "error" : "<ERROR_MESSAGE_STRING>" }
- Code: 404 NOT FOUND
Create a poll
Create a new poll and return its id
-
URL
/poll
-
Method:
POST
-
URL Params
None
-
Data Params
Required:
options=[string][]
Optional:
title=[alphanumeric]
dupeCheckMode="ip" | "cookie" | "none"
multiSelect=[boolean]
-
Success Response:
- Code: 200
Content:{ "id": "abcd1234" }
- Code: 200
-
Error Response:
- Code: 400 BAD REQUEST
Content:
Possible Error Messages:{ "error" : "<ERROR_MESSAGE_STRING>" }
Options must be an array and have at least 2 different entries
Only <<MAX_POLL_OPTIONS>> options are allowed
OR
- Code: 500 INTERNAL SERVER ERROR
Content:{ "error" : "<ERROR_MESSAGE_STRING>" }
- Code: 400 BAD REQUEST