html은 GET 과 POST만 지원 하는데, 그 이유는 the WHATWG HTML 5 specification인 ian ‘hixie’ hickson의 다음과 같은 말에서 볼 수있다.
“PUT as a form method makes no sense, you wouldn’t want to PUT a form payload. DELETE only makes snese if ther is no payload, so it doesn’t make much sense with forms either.”
html 에서 GET, POST를 사용하기위해 “method-override”를 이용했다.
$ npm install method-override
method-override를 install 한다.
var methodOverride= require('method-override')
app.use(methodOverride('_method'))
<app.js>
app.js에 위의 코드를 추가 한다.
<form> method="POST" action="/resource?_method=DELETE">
<button> type="submit">Delete resource</button>
</form>
method에는 POST를 적어줘야한다. (GET이나 다른것을 사용할때는 작동하지 않았다.)
action의 resouce에는 경로를 지정해 주고 뒤는 ?_method=DELETE 또는 ?_method=PUT을 적어 주면 된다.
https://www.npmjs.com/package/method-override
'Framework > node.js' 카테고리의 다른 글
Fetch (0) | 2023.09.17 |
---|---|
Node.js에서 alert 사용 및 페이지 이동 (0) | 2023.08.16 |