
Soul 설치:
npm install -g soul-cli
프로젝트 구조 설정:
API 정의:
- api.js 파일에 원하는 API 엔드포인트와 해당 핸들러 함수를 정의한다.
- 각 핸들러 함수는 req(요청), res(응답), db(데이터베이스 연결) 매개변수를 받는다.
예제
```jsx
//api.js
const getAllOrders = {
method: 'GET',
path: '/api/getAllOrders',
handler: (req, res, db) => {
try {
// order_info
const orderInfoSql = 'SELECT * FROM order_info';
const orderInfo = db.prepare(orderInfoSql).all();
// order_item
const orderItemSql = 'SELECT * FROM order_item';
const orderItem = db.prepare(orderItemSql).all();
const result = {
order_info: orderInfo,
order_item: orderItem,
message: 'Successfully retrieved all orders',
};
res.status(200).json(result);
} catch (error) {
res.status(500).json({
error: error.message,
message: 'Failed to retrieve orders',
});
}
},
};
module.exports = {
getAllOrders,
};
```
Soul 실행:
soul -d "<SQLite DB 파일 경로>" -p <포트 번호> -e "<extensions 폴더 경로>"
API 테스트:
보안 설정:
이러한 방식으로 Soul을 사용하면 SQLite 데이터베이스에 RESTful API를 통해 원격으로 접근할 수 있으며, 이는 POS 시스템의 데이터를 외부 시스템과 연동하거나 원격 모니터링을 구현할 때 유용하게 활용할 수 있다.
soul github: https://github.com/thevahidal/soul