我正在构建一个简单的REST API(使用PouchDB和Vue.js)。现在,我可以创造projects
有几个领域:如何将参数传递给Express post HTTP方法?
server.js:
var express = require('express')
var PouchDB = require('pouchdb')
var app = express()
var db = new PouchDB('vuedb')
app.post('/projects/new', function(req, res) {
var data = {
'type': 'project',
'title': '',
'content': '',
'createdAt': new Date().toJSON()
}
db.post(data).then(function (result) {
// handle result
})
})
client.js:
// HTML
<input type="text" class="form-control" v-model="title" placeholder="Enter title">
<input type="text" class="form-control" v-model="content" placeholder="Enter content">
<button class="btn btn-default" v-on:click="submit">Submit</button>
// JS
submit() {
this.$http.post('http://localhost:8080/projects/new').then(response => {
// handle response
})
}
如何传递参数来设置title
和content
?在REST API中这样做的传统方式是什么?
网址参数:'HTTP://本地主机:8080 /项目/新标题=外国人和内容= scream' ... Express有方法('req.params'我认为)选择这些值。 – Andy