Skip to content

Commit

Permalink
add httpclient example
Browse files Browse the repository at this point in the history
  • Loading branch information
jalpp committed Apr 4, 2024
1 parent d0c85a2 commit 0fcfe37
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 0 deletions.
1 change: 1 addition & 0 deletions example/httpclient-examples/node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
12 changes: 12 additions & 0 deletions example/httpclient-examples/node/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Lichess Nodejs Axios Http Client Example

This directory contains code snippets to make API calls in popular nodejs http client axios,
to run the example follow the steps below. Please note this examples only contain non-OAuth endpoints,
for OAuth endpoints view ```oauth-app```

```
npm install
node server.js
```
165 changes: 165 additions & 0 deletions example/httpclient-examples/node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions example/httpclient-examples/node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"axios": "^1.6.8"
}
}
36 changes: 36 additions & 0 deletions example/httpclient-examples/node/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const axios = require('axios');


//This file contains Lichess API Axios examples, only non OAuth api endpoints are covered


// USER: Real time user status: <https://lichess.org/api#tag/Users/operation/apiUsersStatus>

// Define the query parameters
const queryParams = {
ids: 'aliquantus,chess-network,lovlas', // Example IDs
withGameIds: true // Include game IDs
};

// Make the Axios call
axios.get('https://lichess.org/api/users/status', { params: queryParams })
.then(response => {
console.log(response.data);
// Handle the response data here
})
.catch(error => {
console.error('Error:', error);
// Handle errors here
});


// USER: Get top10 Leaderboard <https://lichess.org/api#tag/Users/operation/player>

axios.get('https://lichess.org/api/player')
.then(response => {
console.log(response.data)
})
.catch(error => {
console.error('Error:', error);
// Handle errors here
});

0 comments on commit 0fcfe37

Please sign in to comment.