Skip to Content
網頁應用程式設計--使用 Node 和 Express
book

網頁應用程式設計--使用 Node 和 Express

by Ethan Brown
December 2014
Intermediate to advanced
336 pages
6h 34m
Chinese
GoTop Information, Inc.
Content preview from 網頁應用程式設計--使用 Node 和 Express
REST API JSON
|
175
我們的資料存儲
同樣的,我們會使用 Mongoose 建立一個資料庫中景點模型的架構。建立檔案
models/
attraction.js
var mongoose = require('mongoose');
var attractionSchema = mongoose.Schema({
name: String,
description: String,
location: { lat: Number, lng: Number },
history: {
event: String,
notes: String,
email: String,
date: Date,
},
updateId: String,
approved: Boolean,
});
var Attraction = mongoose.model('Attraction', attractionSchema);
module.exports = Attraction;
因為我們想要審核更新,所以不能讓 API 隨便更新原始記錄。我們的方法是建立一筆參
考原始記錄的新記錄(在它的
updateId
特性)。當記錄被審核之後,我們可以將原始記
錄更新為更新記錄裡面的資訊,接著刪除更新記錄。
我們的測試
如果我們使用 HTTP 動詞而不是
GET
,對於測試我們的 API 而言,將是件麻煩事,因為
瀏覽器只知道如何發出
GET
請求(及表單的
POST
請求)。有一些方法可以處理這種情
況,例如很棒的“Postman ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

HTML5與JAVASCRIPT WEB APPS開發實務

HTML5與JAVASCRIPT WEB APPS開發實務

Wesley Hales
jQuery Mobile建置與執行

jQuery Mobile建置與執行

Maximiliano Firtman

Publisher Resources

ISBN: 9789863474371