Skip to content

Commit 37be07b

Browse files
committed
initial commit
1 parent 874a825 commit 37be07b

File tree

4 files changed

+108
-1
lines changed

4 files changed

+108
-1
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Apioo
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+54-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,54 @@
1-
# https-github.com-apioo-fusio-sample-javascript-cli
1+
2+
Fusio JavaScript CLI sample
3+
=====
4+
5+
# About
6+
7+
This is a simple JavaScript CLI application which shows how to use the JavaScript SDK to access a Fusio instance.
8+
In this example we simply output all registered operations.
9+
Fusio is an open source API management which helps to build and manage great APIs more information at:
10+
https://www.fusio-project.org/
11+
12+
```javascript
13+
const {Client} = require('fusio-sdk');
14+
const {OAuth2, MemoryTokenStore} = require('sdkgen-client');
15+
16+
async function main() {
17+
const tokenStore = new MemoryTokenStore();
18+
const scopes = ["backend"];
19+
20+
const credentials = new OAuth2(
21+
"test",
22+
"FRsNh1zKCXlB",
23+
"https://demo.fusio-project.org/authorization/token",
24+
"",
25+
tokenStore,
26+
scopes
27+
);
28+
29+
const client = new Client("https://demo.fusio-project.org", credentials)
30+
31+
console.log("Operations:")
32+
const collection = await client.backend().operation().getAll(0, 16, "")
33+
34+
for (const operation of collection.entry) {
35+
console.log(" * " + operation.httpMethod + " " + operation.httpPath)
36+
}
37+
}
38+
39+
main();
40+
```
41+
42+
# Run
43+
44+
To run the demo you simply need to install all dependencies.
45+
46+
```
47+
npm install
48+
```
49+
50+
and then you can execute the main script.
51+
52+
```
53+
node main.cjs
54+
```

main.cjs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
const {Client} = require('fusio-sdk');
3+
const {OAuth2, MemoryTokenStore} = require('sdkgen-client');
4+
5+
async function main() {
6+
const tokenStore = new MemoryTokenStore();
7+
const scopes = ["backend"];
8+
9+
const credentials = new OAuth2(
10+
"test",
11+
"FRsNh1zKCXlB",
12+
"https://demo.fusio-project.org/authorization/token",
13+
"",
14+
tokenStore,
15+
scopes
16+
);
17+
18+
const client = new Client("https://demo.fusio-project.org", credentials)
19+
20+
console.log("Operations:")
21+
const collection = await client.backend().operation().getAll(0, 16, "")
22+
23+
for (const operation of collection.entry) {
24+
console.log(" * " + operation.httpMethod + " " + operation.httpPath)
25+
}
26+
}
27+
28+
main();

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"fusio-sdk": "^5.1.15"
4+
}
5+
}

0 commit comments

Comments
 (0)