jeudi 26 mai 2016

ember-data with customization for use with non-JSONAPI service

I am a bit confused and just need some clarity: Should I be implementing a custom adapter or a custom serializer?

I need my ember app to talk to a REST/json backend.

I want my ember app to expose the resource as:

GET /locations/:id

But the host it connects to has the resource located at:

GET http://server/api/location/:id

Payload from the server:

{
  "id": "7ff3269e-d16c-4cc4-954d-aef8e662e0f6",
  "geo": {
    "latitude": 0,
    "longitude": 0
  },
  "typedAddress": {
    "addressType": "US",
    "countryCode": "US",
    "name": "string",
    "address1": "string",
    "address2": "string",
    "address3": "string",
    "postalCode": "string"
  },
  "customDescription": "string",
  "timezone": "string"
}

My model in ember for this:

export default Model.extend({
  latitude: attr('number'),
  longitude: attr('number'),
  addressType: attr('string'),
  countryCode: attr('string'),
  address1: attr('string'),
  address2: attr('string'),
  address2: attr('string'),
  city: attr('string'),
  state: attr('string'),
  briefPostalCode: attr('string'),
  postalCode: attr('string'),
  timezone: attr('string')
});




Aucun commentaire:

Enregistrer un commentaire