@xapi-js/adaptor-express 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +115 -29
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,29 +1,115 @@
|
|
|
1
|
-
# @xapi-ts/adaptor-express
|
|
2
|
-
|
|
3
|
-
This package provides an Express.js adaptor for X-API data.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
#
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
# @xapi-ts/adaptor-express
|
|
2
|
+
|
|
3
|
+
This package provides an Express.js adaptor for X-API data.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# npm
|
|
9
|
+
npm install @xapi-ts/adaptor-express
|
|
10
|
+
|
|
11
|
+
# yarn
|
|
12
|
+
yarn add @xapi-ts/adaptor-express
|
|
13
|
+
|
|
14
|
+
# pnpm
|
|
15
|
+
pnpm add @xapi-ts/adaptor-express
|
|
16
|
+
|
|
17
|
+
# bun
|
|
18
|
+
bun add @xapi-ts/adaptor-express
|
|
19
|
+
|
|
20
|
+
# deno
|
|
21
|
+
deno add @xapi-ts/adaptor-express
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
Here's how to use `@xapi-ts/adaptor-express` with an Express application:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import express from 'express';
|
|
30
|
+
import { xapiExpress } from '@xapi-ts/adaptor-express';
|
|
31
|
+
import { XapiRoot } from '@xapi-ts/core';
|
|
32
|
+
|
|
33
|
+
const app = express();
|
|
34
|
+
|
|
35
|
+
// Define your X-API handler function
|
|
36
|
+
const xapiHandler = async (xapi: XapiRoot): Promise<XapiRoot> => {
|
|
37
|
+
// Process the incoming X-API request (xapi)
|
|
38
|
+
// For example, you can access parameters or datasets:
|
|
39
|
+
const service = xapi.parameters.get('service')?.value;
|
|
40
|
+
console.log(`Service requested: ${service}`);
|
|
41
|
+
|
|
42
|
+
// Create a response X-API object
|
|
43
|
+
const responseXapi = new XapiRoot();
|
|
44
|
+
responseXapi.addParameter({ id: 'result', value: 'success' });
|
|
45
|
+
return responseXapi;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Use the xapiExpress middleware
|
|
49
|
+
app.use('/xapi', xapiExpress(xapiHandler));
|
|
50
|
+
|
|
51
|
+
// Start the server
|
|
52
|
+
const PORT = 3000;
|
|
53
|
+
app.listen(PORT, () => {
|
|
54
|
+
console.log(`Express server listening on port ${PORT}`);
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
# @xapi-ts/adaptor-express
|
|
61
|
+
|
|
62
|
+
이 패키지는 X-API 데이터를 위한 Express.js 어댑터를 제공합니다.
|
|
63
|
+
|
|
64
|
+
## 설치
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# npm
|
|
68
|
+
npm install @xapi-ts/adaptor-express
|
|
69
|
+
|
|
70
|
+
# yarn
|
|
71
|
+
yarn add @xapi-ts/adaptor-express
|
|
72
|
+
|
|
73
|
+
# pnpm
|
|
74
|
+
pnpm add @xapi-ts/adaptor-express
|
|
75
|
+
|
|
76
|
+
# bun
|
|
77
|
+
bun add @xapi-ts/adaptor-express
|
|
78
|
+
|
|
79
|
+
# deno
|
|
80
|
+
deno add @xapi-ts/adaptor-express
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## 사용법
|
|
84
|
+
|
|
85
|
+
다음은 Express 애플리케이션에서 `@xapi-ts/adaptor-express`를 사용하는 방법입니다:
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import express from 'express';
|
|
89
|
+
import { xapiExpress } from '@xapi-ts/adaptor-express';
|
|
90
|
+
import { XapiRoot } from '@xapi-ts/core';
|
|
91
|
+
|
|
92
|
+
const app = express();
|
|
93
|
+
|
|
94
|
+
// X-API 핸들러 함수 정의
|
|
95
|
+
const xapiHandler = async (xapi: XapiRoot): Promise<XapiRoot> => {
|
|
96
|
+
// 들어오는 X-API 요청(xapi) 처리
|
|
97
|
+
// 예를 들어, 파라미터 또는 데이터셋에 접근할 수 있습니다:
|
|
98
|
+
const service = xapi.parameters.get('service')?.value;
|
|
99
|
+
console.log(`Service requested: ${service}`);
|
|
100
|
+
|
|
101
|
+
// 응답 X-API 객체 생성
|
|
102
|
+
const responseXapi = new XapiRoot();
|
|
103
|
+
responseXapi.addParameter({ id: 'result', value: 'success' });
|
|
104
|
+
return responseXapi;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// xapiExpress 미들웨어 사용
|
|
108
|
+
app.use('/xapi', xapiExpress(xapiHandler));
|
|
109
|
+
|
|
110
|
+
// 서버 시작
|
|
111
|
+
const PORT = 3000;
|
|
112
|
+
app.listen(PORT, () => {
|
|
113
|
+
console.log(`Express server listening on port ${PORT}`);
|
|
114
|
+
});
|
|
115
|
+
```
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xapi-js/adaptor-express",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"express": "^5.1.0",
|
|
34
|
-
"@xapi-js/core": "1.
|
|
34
|
+
"@xapi-js/core": "1.1.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/express": "^5.0.3",
|