koji-leaderboard-api
📦 Koji Database based Leaderboard API setup, at your doorsteps.
When you create games or any competitive webapp on Koji, you need to have Leaderboards. Setting them up in the backend could sometimes be a horrific task. So, you have this simple plugNplay Express API that runs smoothly with the most minimal setup!
💃 Documentation
koji-leaderboard-api
Install To install the API on your Node.js backend, run the following.
$ npm i -S koji-leaderboard-api
Summary
- 1st parameter:
app
👉 (type:Express App Instance
, Required) - 2nd parameter:
tableName
👉 (type:String
, Optional, Default:leaderboard
) - The table name you want your data to be stored under. For eg. if yourtableName
isleaderboard
, then your API endpoints will beGET /leaderboard
andPOST /leaderboard
.
Usage
See the following example 👇
const app = // This is the Express App Instance // Body parserappapp // CORSapp /** * @name kojiLeaderboardApi * @description Doing `kojiLeaderboardApi(app)` activates the `/leaderboard` GET and POST API endpoints * that your frontend can use to Display and Update Leaderboard * * @param {Express App Instance} app - (required) * @param */ // Listen on Port 8080. Visit http://localhost:8080 to see the backend.app
In the above example, we make use of an express server. What you need to do, is to just pass the Express App Instance
as the only parameter to the kojiLeaderboardApi()
function. That activates your Leaderboard API.
API Endpoints
Method | Endpoint | Parameters (JSON Body) | |
---|---|---|---|
1 | GET | /leaderboard |
- |
2 | POST | /leaderboard |
name: String 👈 required score: Number 👈 required privateAttributes: Object 👈 optional |
Important note: The above mentioned API endpoints only work if you haven't filled in the second parameter. If you have, the second parameter will be your GET and POST endpoint.
/leaderboard
GET JavaScript fetch example
{ const response = await return response}
Successful Example Response 👇
/leaderboard
POST Parameters
The parameters have to be a Body in a JSON format, to be processed correctly.
name
👉 String: { strLength should be more than 3 } (required)score
👉 Number: { Score should be more than 1 } (required)privateAttributes
👉 Object or null (optional) The Object can contain email, or any private information that shouldn't be accessed from theGET /leaderboard
endpoint.
JavaScript fetch example
{ const body = name: "Kumar Abhirup" score: 5280 privateAttributes: email: "kumarsExampleMail@gmail.com" await }
Successful Example Response 👇
📝 License
MIT © Kumar Abhirup
Follow me 👋 on Twitter →