ASP .NET
  • Introduction
  • Chapter1.MVC 5
    • 1.1.The Complete ASP.NET MVC 5 Course
      • 1.0. Deploy .NET project to IIS
      • 1.1.Getting started
        • 1.1.1.MVC Architectural
        • 1.1.2.Setting up the development environment
        • 1.1.3.Create MVC APP
        • 1.1.4.Add a new Model, Controller, View
      • 1.2.ASP.NET MVC Fundamentals
        • 1.2.1.Action
        • 1.2.2.Route
        • 1.2.3.Pass data to views
        • 1.2.4.ViewModel
        • 1.2.5.View
      • 1.3.Working with data
        • 1.3.1.Entity framework
        • 1.3.2.Database First v.s. Code First
        • 1.3.3.Code-first Migrations
        • 1.3.4.Seeding the database
        • 1.3.5.Overriding conventions
        • 1.3.6.Query objects
      • 1.4.Building Forms
        • 1.4.1.The Markup (labelFor, textbox, checkbox)
        • 1.4.2.Labels
        • 1.4.3.Drop down list
        • 1.4.4.Model binding and save data
        • 1.4.5.Edit form
      • 1.5.Implement validation
        • 1.5.1.Adding validation
        • 1.5.2.Data annotation
        • 1.5.3.Client side validation
        • 1.5.4.Anti-forgery Tokens
      • 1.6. Building RESTful API
        • 1.6.1. What is Web API?
        • 1.6.2. RESTful convetion
        • 1.6.3. Building a API and testing
        • 1.6.4. Data Transfer Object
        • 1.6.5. Use camel annotation
        • 1.6.6. Use IHttpActionResult
      • 1.7.Client-side Development
        • 1.7.1.Calling an API using jQuery
        • 1.7.2.Bootbox plug-in
        • 1.7.3.DataTable plug-in using AJAX source
        • 1.7.4.Returning Hierarchical Data
      • 1.8.Authentication and Authorization
        • 1.8.1.The problem
        • 1.8.2.Authentication options
        • 1.8.3.Restricting Access
        • 1.8.4.Seeding Users and Roles
        • 1.8.5.Working with Roles
        • 1.8.6.Adding Profile Data
        • 1.8.7.OAuth
        • 1.8.8.Social Logins
      • 1.9.Performance Optimization
        • 1.9.1.Overview
        • 1.9.2.Data Tier
        • 1.9.3.Glimpse
        • 1.9.4.Output Cache
        • 1.9.5.Data Cache
        • 1.9.6.Async
        • 1.9.7.Disabling Session
        • 1.9.8.Client Tier
      • 1.10.Building a Feature End-to-End Systematically
        • 1.10.1.Domain Modelling
        • 1.10.2.Adding Auto-completion
        • 1.10.3.Updating the DOM
        • 1.10.4.Implementing Client-side Validation
      • 1.11.Deployment
        • 1.11.1.Deploying the application
        • 1.11.2.Deploying the database
        • 1.11.3.Build configurations
        • 1.11.4.Application settings
        • 1.11.5.Custom Error Pages
        • 1.11.6.Logging Unhandled Exceptions
      • 1.12.Approved collection server
        • 1.12.1.Overview
        • 1.12.2.測試上傳審批資料
        • 1.12.3.取得Token的方式
        • 1.12.4.測試取得審批資料, Log資料
        • 1.12.5.將API接口綁定到雲之家審批
    • 1.2.Skilltree MVC 實戰營筆記
      • 1.2.1..NET MVC overview and razor view
      • 1.2.2.Controller, Model, Entity framework, service
      • 1.2.3.HTML helper, Extension method, Validation
      • 1.2.4.Security, ActionFilter, ActionResult
      • 1.2.5.DataType, Templates
  • Chapter2.SignalR
    • 2.1.Getting started
      • 2.1.1.Install signalR on VS2013
    • 2.2.Basic of SignalR
      • 2.2.1.Chat App Ovierview
      • 2.2.2.Creating a hub
      • 2.2.3.Connecting to the hub
      • 2.2.4.Create A server method and calling from client
      • 2.2.5.Passing parameters to server method from client
      • 2.2.6.Creating a client method and calling from server
    • 2.3. Exploring the class hub and group chat
      • 2.3.1.OnConnected, OnDisconnected
      • 2.3.2. ContextObject and JSON serialization
      • 2.3.3. Clients Object's Methods
      • 2.3.4. Add Or Remove Connection From Groups
      • 2.3.5. Sending Messages To Different Groups
  • Chapter3.REST API Design, Development & Management
    • 3.1.Evolution of RESTful services
      • 3.1.1.Evolution of REST/JSON API
      • 3.1.2.Introduction to RESTful API
      • 3.1.3.Private, Public and Partner API
    • 3.2.REST API Architectural Constraints
      • 3.2.1.Introduction to REST Architecture Constraints
      • 3.2.2.Client-Server
      • 3.2.3.Uniform Interface
      • 3.2.4.Statelessness
      • 3.2.5.Caching
      • 3.2.6.Layered system
      • 3.2.7.Code on demand
      • 3.2.8.Richardson Maturity Model for REST API
    • 3.3.Designing REST API
      • 3.3.1.API value chain
      • 3.3.2.Practices for Resource Names, Actions & Associations
      • 3.3.3.Implementing REST API CRUD operations
      • 3.3.4.Walkthrough: Creating a Vacations API in Node JS
      • 3.3.5.REST API Error Handling Practices
      • 3.3.6.Walkthrough: Implementation of error handling for POST API
      • 3.3.7.Versioning the API
      • 3.3.8.API Caching (1 of 2) Concepts & Design decisions
      • 3.3.9.API Caching (2 of 2) Concepts & Design decisions
      • 3.3.10. Demo - API Caching using Cache-Control Directives
      • 3.3.11.Building support for Partial Responses
    • 3.4.REST API Security
      • 3.4.1.REST API Security - Introduction
      • 3.4.2.Securing API with Basic Authentication
      • 3.4.3.Securing API with Tokens & JWT
      • 3.4.4.Securing API with API Key & Secret
      • 3.4.5.API Authorization using OAuth2.0
        • 3.4.5.1.Authorization scope grant (Refresh token grant)
        • 3.4.5.2.Client credentials grant
        • 3.4.5.3.Implicit Grant
        • 3.4.5.4.Resource owner credentials grant
      • 3.4.6.API Security - Functional Attack
    • 3.5.REST API Specifications using Swagger 2.0 / OAI
      • 3.5.1.Requirements Analysis Process & Intro to REST Specifications
      • 3.5.2.Swagger/OAI Specifications Walkthrough
      • 3.5.3.Swagger/OAI Specifications, Part 1 of 3
      • 3.5.4.Swagger/OAI Specifications, Part 2 of 3
      • 3.5.5.Swagger/OAI Specifications, Part 3 of 3
    • 3.6.API management
      • 3.6.1.Introduction to API Management
      • 3.6.2.API Lifecycle & Developer Productivity
      • 3.6.3.API Developer Portal
      • 3.6.4.API Security management
      • 3.6.5.API Traffic Management
      • 3.6.6.API Analytics
      • 3.6.7.API Product and API Monetization
    • 3.7.Summary
  • Chapter4.REST API/Web Services testing with SoapUI
    • 4.1.Web Service Basics
      • 4.1.1.Introduction of WSDL
      • 4.1.2.Introduction of SOAP
      • 4.1.3.Introduction to XML
    • 4.2.SoapUI Basics
      • 4.2.1.Create TestSuite and TestCase
      • 4.2.2.Exporting and Importing project into workspace
      • 4.2.3.Running mock service- might come handy when your actual service is down
    • 4.3.Assertion
      • 4.3.1.XPath Expression
      • 4.3.2.Writing first assertion
      • 4.3.3.Assertions - Compliance,Status & Standards
      • 4.3.4.XQuery assertion
      • 4.3.5.Handling CDATA - using XPath and Groovy
    • 4.4.Working with Properties
      • 4.4.1.Property expansion
Powered by GitBook
On this page

Was this helpful?

  1. Chapter3.REST API Design, Development & Management
  2. 3.3.Designing REST API

3.3.11.Building support for Partial Responses

Previous3.3.10. Demo - API Caching using Cache-Control DirectivesNext3.4.REST API Security

Last updated 5 years ago

Was this helpful?

  • Partial Responses

    • "API consumer" in control of response

    • 例如mobile的使用者可能不需要取得完整的資料, Partial Responses可以讓使用者指定特定的欄位

  • Benefits

    • Better performance & optimized resource usage

      • CPU, Memory, Bandwidth

    • API consumer controls the granularity

    • Common API version for all consumers

      • to support multiple devices, use cases - form factors

  • Specifiction

    • Depends on the platform/language/DB

    • : /people: (id, first-name, last-name)

    • facebook: /friend?fields=id,name,picture

    • Pinterest: /pins?fields=id,link,creator(first_name)

  • Requirements

      • Add collection -> 新增一個叫hotels的collection

      • Add database user -> 新增一個叫xxx的user

      • collection-> index -> add index

        • { "name": 1}, 勾選unique

      • 1.clone repository

        git clone https://github.com/acloudfan/REST-API-Course.git
        cd REST-API-COURSE/
        git checkout partialresponse
        npm install
      • 2.將資料寫到DB

        • 設定連線字串

          • 到mlab的database頁面下, 複製連線字串

          • 開啟專案, 修改tests/TestHotelsDBOps.js的process.env.DB_URI

          • 開啟檢視/ 偵錯主控台/ 終端機, 輸入

               node tests/TestHotelsDBOps
      • 3.程式碼解析

        • 的作法是用

     module.exports = function(router){
    'use strict';

    router.route(URI).get(function(req, res,next){
        console.log("GET Hotels")

        //1. fields
        var fields ={}
        if(req.query && req.query.fields !== undefined){
           fields =  createFields(req.query.fields)
        }

        //2. Setup options
        var options = {fields:fields}
        console.log(options)

        //3. execute the query
        var criteria = {}
        db.select(criteria, options, function(err,docs){

            if(err){
                console.log(err)
                res.status(500)
                res.send("Error connecting to db")
            } else {
                if(docs.length == 0){
                    res.status(404)
                }
                console.log("Retrieved hotels = %d",docs.length)
                res.send(docs)
            }
        });
    });
    }

    // RETRIEVE hotels packages based on criteria & fields
// https://docs.mongodb.com/manual/reference/method/db.collection.find/#find-projection
// options = {
//    fields: {/** Projection **/}
// }
exports.select = function (criteria,options, callback) {
    model.Hotels.find(criteria, function (err, data) {
        callback(err, data)
    }).select(options.fields)
}
Linkedin
Visual studio code
node.js
mlab
source code from github
mongoDB
projection