32
BEST PRACTICES and what things to avoid

Api best practices

Embed Size (px)

DESCRIPTION

Ten Tips on the FamilySearch Partner API.

Citation preview

Page 1: Api best practices

BEST PRACTICESand what things to avoid

Page 2: Api best practices

Sometimes the specification is misunderstood, or relevant parts of the specification are missed or not documented well.

Page 3: Api best practices

Tip #1

To specify the type of data returned from a call to the API, avoid using .xml and .json on the URL.

Instead:Use Accept header for a GETUse Content-Type for a POST and PUT

Page 4: Api best practices

Examples

GET /platform/tree/ancestry.xml?person=PS11-234

VS.

GET /platform/tree/ancestry?person=PS11-234Accept: application/x-fs-v1+xml

Page 5: Api best practices

Tip #2

For the media-type header, use the version media type instead of “application/xml” or “application/json”

Page 6: Api best practices

Example

Accept: application/x-fs-v1+xml

Accept: application/x-gedcomx-v1+xml

Page 7: Api best practices

Example

Page 8: Api best practices

Tip #3

List media types using commas

Page 9: Api best practices

Example

Accept: application/x-gedcomx-v1+xml, application/atom+xml,application/xml

Page 10: Api best practices

Tip #4

Use the Authorization header instead of the access_token stringparameter

Authorization: Bearer {access_token}

Page 11: Api best practices

Example

Authorization: Bearer USYSblahblahblahfsglobal.net

Page 12: Api best practices

Tip #5

Access tokens expire after 1 hour of inactivityor after 24 hours

Whichever comes first

Page 13: Api best practices

Tip #6

Watch out for conflicting cookies between sandbox and production

Example: access token cookie

Page 14: Api best practices

Tip #7

Use the Warning header to understand errors from FamilySearch.

e.g.Warning: blah blah blah

Page 15: Api best practices

Tip #8

Watch for pending modifications athttps://familysearch.org/platform/pending-modifications

Page 16: Api best practices

Example

Page 17: Api best practices

Tip #9

Use the “X-FS-Feature-Tag” Header

Page 18: Api best practices

API Evolution Guide

Dealing with Change

Page 19: Api best practices

API Evolution Guide

Changes regarding the protocolChanges regarding resourcesChanges regarding resource representations

Page 20: Api best practices

Changes Regarding Protocol

When the FamilySearch API is using HTTP insufficiently or incorrectly

Page 21: Api best practices

Changes Regarding Resources

Resources are units of information• Person in the tree• Source description• Photo• Search results

Page 22: Api best practices

Changes Regarding Resources

Resources change because:User - merged duplicate peopleSystem – resource in database is denormalized

Page 23: Api best practices

Resource Representations Changes

GEDCOM X for genealogical dataExtensions for custom and proprietary resources

Page 24: Api best practices

Resource Representations Changes

Data format changes -adding propertiesremoving propertieschanging the datatype of a property value

Page 25: Api best practices

Changes

Compatible ChangesIncompatible Changes

Page 26: Api best practices

Compatible Changes

Examples:Additive ChangesSemantically-Equivalent

Page 27: Api best practices

Incompatible Changes

Examples:Deletion of propertiesChanges to the datatypes of property values

Page 28: Api best practices

Rollout of Incompatible Changes

Pending Modificationshttps://familysearch.org/platform/pending-modifications

HTTP Request Header“X-FS-Feature-Tag” value is a comma delimited list of labels from the

pending modification page

Page 29: Api best practices

Example

X-FS-Feature-Tag: remove-identity-v2-login,birth-date-not-considered-death-declaration

Page 30: Api best practices

Tip #10

Use Hypermedia to drive your application state

Page 31: Api best practices

Reason• In case of compatible changes, your client is:

• More adaptable• More Robust • More Maintainable• Less Pain

Page 32: Api best practices

Reason• The API makes compatible changes without breaking the

clients• The client detect changes to resources through the

hypermedia