CLI와 HATEOAS를 결합한 Todo 목록
8314 단어 hypermedianodeclihateoas
app.get('/notes', (req, res) => {
const rawNotesList = fs.readFileSync('../cli/notes.json', {encoding: 'utf8', flag: 'r'});
const parsedNotesList = JSON.parse(rawNotesList);
const links = [
{
rel: ["self"],
href: [baseUrl, '/notes'].join('')
}
];
const actions = [
{
class: "add-note",
href: [baseUrl, '/notes'].join(''),
method: 'POST',
fields: [
{
name: "command",
type: "string"
},
{
name: "content",
type: "string"
}
]
}
];
const responseWithControlData = {
class: "note",
...parsedNotesList,
links: links,
actions: actions
};
res.json(responseWithControlData);
});
그리고:
app.post('/notes', (req, res) => {
const body = req.body;
if (!body.command.includes('add')) {
return res.status(400).json({
status: 'failed to add content',
content: body.content
});
}
const cliCapture = new CliCapture({
notesPath: './notes.json',
command: body.command,
content: body.content
});
res.json({
status: 'added from server'
});
});
우리는 이 CoAP/CoRE 및 Amundsen의 DARRT 접근 방식을 유추할 수 있습니다. "CliCapture"를 실제로 대체할 수 있는 모든 것과
fs
를 사용할 수 있는 곳이라면 어디에서나 리소스 디렉터리를 HTTP( https://github.com/JelmerT/coap-rd/blob/master/requesthandlers.js#L82 )에 매핑하여 기능을 확장할 수 있습니다.https://github.com/nerdfiles/notes-cli/blob/master/cli/server/index.js#L19-L56 및 https://github.com/nerdfiles/notes-cli/blob/master/cli/server/index.js#L69-L73 참조
Reference
이 문제에 관하여(CLI와 HATEOAS를 결합한 Todo 목록), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/dualyticalchemy/todo-list-combining-cli-and-hateoas-14b0텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)