FamilySearch/fs-js-lite

Optional deserialization with gedcomx-fs-js

Closed this issue · 4 comments

Add option for deserializing with gedcomx-fs-js.

The library will be provided when the client is created. The response.data property will be a gedcomx-js object instead of a plain JSON object.

I need to detect the response type so that I can instantiate the correct class from gedcomx-fs-js. I'm having a little trouble due to two different error formats and more. So here I'll try to document how the Content-Type and other indicators differ based on the request.

Atom

Responses include an entries property.

Response Content-Type

  • application/json when application/json is requested or the .json suffix is used
  • application/x-gedcomx-atom+json when application/x-gedcomx-atom+json is requested

Errors

  • Nested in an array when application/x-fs-v1+json or application/x-gedcomx-v1+json is requested
  • Top level (no array) when application/json is requested

GEDCOMX X and FamilySearch

Response Content-Type

  • application/json when application/json is requested or the .json suffix is used
  • application/x-gedcomx-v1+json when application/x-gedcomx-v1+json is requested
  • application/x-fs-v1+json when application/x-fs-v1+json is requested

OAuth

Content-Type is always application/json for OAuth token responses.

Success

Response has access_token and token_type properties.

Error

Response has error and error_description properties.

When the response Content-Type is not application/json then I know that type it is. When the type is application/json then I'll have to examine the response properties to determine what type it is.

In the FamilySearch API, there is no difference between responses of Content-Type application/x-fs-v1+json and application/x-gedcomx-v1+json. The only difference in the API is that some endpoints Accept both while others only Accept application/x-fs+v1+json. For those that accept both, the response format does not change. In other words, even if you request application/x-gedcomx-v1+json you will still receive data for the FamilySearch extensions to Gedcom X.

I have to wait until I hear back about the error format so I know whether I need to add errors to the FamilySearch response type.

After adding middleware via #2 we can support gedcomx-js without baking it into the core. All we have to do is document how it can be done via middleware and optionally publish the middleware.