Article System APIs - nodejs-camp/booklog-homa GitHub Wiki

Method Version API Path Permission Description MongoDB Ops
GET 1.0 /1/article Public 顯示所有文章 aggregate([$project, $group])
GET 1.0 /1/article/:id Public 顯示指定文章(ID) find({ _id: id })
GET 1.0 /1/article/subject/:subject Public 顯示指定標題的文章 find({ subject: url, isActive: true })
GET 1.0 /1/article/content/:keyword Public 顯示內文存在關鍵字的文章 find({ content: url, isActive: true })
GET 1.0 /1/article/date/publish/:fm/:to Public 顯示時間點內發布的文章 aggregate()
GET 1.0 /1/article/date/create/:fm/:to Login 顯示時間點內建立的文章 aggregate()
POST 1.0 /1/article Public/Login 建立新標題、新文章 save()
PUT 1.0 /1/article Public/Login 建立舊有標題、新文章 save()
PUT 1.0 /1/article/:subject/publish Public/Login 將文章公開 update({ subject: url})
PUT 1.0 /1/article/:subject/unpublish Public/Login 將文章下線 update({ subject: url})
DELETE 1.0 /1/article/:id Admin 刪除指定文章 findByIdAndRemove(_id)

GET /1/post

讀取所有文章資訊

Query String Parameters

No query string

Response

Field Type Description
success integer Backbone status
errors array Backbone status
errfor array Backbone status
posts array 取得的文章資訊

Example

Request:

http://www.mokoversity.com/1/post

Response:

{
    "success": true,
    "errors": [],
    "errfor": {},
    "posts": [{
        "_id": {
            "subject": "Startup CEO Mind:談 Product Key Metrics"
        },
        "date": "2014-01-31T08:14:07.457Z",
        "subject": "Startup CEO Mind:談 Product Key Metrics",
        "isActive": true,
        "id": "52eb5b4f0dca45226f000029",
        "uid": "51c7b9e04471c752cbf7e089"
    }, {
        "_id": {
            "subject": "Node.js 101 觀念重點"
        },
        "date": "2014-01-25T07:13:08.288Z",
        "subject": "Node.js 101 觀念重點",
        "isActive": false,
        "id": "52e36404b9d2010f74000037",
        "uid": "51c7b9e04471c752cbf7e089"
    }]
}

GET /1/post/:id

讀取指定的 ':id' 文章資訊

Query String Parameters

No query string

Response

Field Type Description
success integer Backbone status
errors array Backbone status
errfor array Backbone status
post object 取得的單篇文章資訊

Example

Request:

http://www.mokoversity.com/1/post/52eb5b4f0dca45226f000029

Response:

{
    "success": true,
    "errors": [],
    "errfor": {},
    "post": {
        "_id": "52eb5b4f0dca45226f000029",
        "__v": 0,
        "userCreated": {
            "id": "51c7b9e04471c752cbf7e089",
            "time": "2014-01-31T07:13:26.804Z",
            "name": "jollen"
        },
        "wchars": 409,
        "date": "2014-01-31T08:14:07.457Z",
        "isActive": true,
        "tags": [],
        "html": "",
        "content": "Lean Analytics[1] 一書提到...不重實質層面的 page views 分析\n\n",
        "subject": "Startup CEO Mind:談 Product Key Metrics"
    }
}

GET /1/post/subject/:subject

讀取指定的 ':subject' 文章資訊

Query String Parameters

No query string

Response

Field Type Description
success integer Backbone status
errors array Backbone status
errfor array Backbone status
post object 取得的單篇文章資訊

Example

Request:

http://www.mokoversity.com/1/post/subject/Startup CEO Mind:談 Product Key Metrics

Response:

{
    "success": true,
    "errors": [],
    "errfor": {},
    "post": {
        "_id": "52eb5b4f0dca45226f000029",
        "__v": 0,
        "userCreated": {
            "id": "51c7b9e04471c752cbf7e089",
            "time": "2014-01-31T07:13:26.804Z",
            "name": "jollen"
        },
        "wchars": 409,
        "date": "2014-01-31T08:14:07.457Z",
        "isActive": true,
        "tags": [],
        "html": "",
        "content": "Lean Analytics[1] 一書提到...不重實質層面的 page views 分析\n\n",
        "subject": "Startup CEO Mind:談 Product Key Metrics"
    }
}

POST /1/post

建立新標題、文章,或根據舊標題來建立新文章。設計說明:

  • 以標題做為頁面 URL path;
  • 因此,原則上不能修改標題(SEO 考量);
  • 更新文章的做法,是根據舊標題來 Copy/Modify 原有內容,目的是保留變更紀錄(History)

Query String Parameters

Field MongoDB type Description
id ObjectId 文章的 ID
subject String 標題
content String 內文

Response

Field Type Description
success integer Backbone status
errors array Backbone status
errfor array Backbone status
post object 取得的單篇文章資訊

Example

Request:

Response: