Skip to content

Example Falcor DataSource/Model to wrap existing RESTful resources #513

@baer

Description

@baer

So I've now read all of the docs and watched the keynote + the 8 getting started videos and I'm still not that clear on how Falcor orchestrates data fetching. Furthermore since very few of us are lucky enough to work in greenfield projects I'd imagine a very common use case would be to start by wrapping an existing RESTful API. There are two specific scenariaos that I'm not sure about how to deal with:


  • What would be the preferred way to expose the GET lists vs. GET details pattern. These two models effectively nested.

GET /users

[{
  "id": "123",
  "givenName": "Brandon",
  "surame": "Pricher"
}, {
  ...
}]

GET /users/123

{
    "id": "123",
    "givenName": "Brandon",
    "surame": "Pricher",
    "customerLifetimeValue": "909869.00",
    "preferredLocale": "en-US",
}

  • To extend the above, lets say my view needs the Customer + the customer's address. Lets assume we have a user model but the address is an external lookup (USPS address validation for example). On the client sideI might deal with this as follows in the controller but the model seems to have some of this information already encoded in it. Furthermore, if a Falcor client doesn't request address, there is no reason to make that call. Does Falcor orchestrate dependent queries or is there a proper way to handle this?
getCustomerViewModel(id) {
  let customer = getCustomer(id)
  let address = customer.then(getCustomerAddress)

  return Promise.all(customer, address)
    .then((customer, address) => {
      return customer.address = address;
    }).catch(errorHandler)
}

This is what the view actually needs to render the page

{
    "id": "123",
    "givenName": "Brandon",
    "surame": "Pricher",
    "customerLifetimeValue": "909869.00",
    "preferredLocale": "en-US",
    "address": {
      "street": 123,
      "city": "Memphis",
      "zip": "38120-0098" 
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions