Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft for Sourcing from Private APIs #9772

Merged
merged 5 commits into from
Nov 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions docs/docs/sourcing-from-private-apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,25 @@
title: Sourcing from Private APIs
---

This is a stub. Help our community expand it.
Gatsby allows you to pull data from headless CMSs, databases, SaaS services, public API, and your private APIs.

Please use the [Gatsby Style Guide](/docs/gatsby-style-guide/) to ensure your
pull request gets accepted.
From the Gatsby perspective, there is no difference between sourcing from a public or private API. The only difference is the availability of the API to Gatsby to query the data.

There are 3 approaches that you can use to source data from your private API:

1. If your private API is a GraphQL API, you can use [`gatsby-source-graphql`](https://www.gatsbyjs.org/packages/gatsby-source-graphql/).
2. If your private API is not a GraphQL API and you are new to GraphQL, treat the data as unstructured data and fetch it during build time, as described by the guide "[Using unstructured data](/docs/using-unstructured-data/)". However, as highlighted in the guide, this approach comes with some tradeoffs.
3. Create a source plugin, as described in the tutorial "[Source plugin tutorial](/docs/source-plugin-tutorial/)".

### Other considerations

1. If the data of your private API is updated very frequently or the expectation of the site is to be updated in real-time, it may make more sense to query the data directly during runtime.

2. If you can source the data through a plugin, consider that as an alternative to sourcing via the API. For instance, if you have access to the MongoDB database that stores the data, [`gatsby-source-mongodb`](/https://www.gatsbyjs.org/packages/gatsby-source-mongodb/) will be handy. Browse the [Gatsby Plugin Library](https://www.gatsbyjs.org/plugins/) to see what plugins that you could utilize.

3. Depending on your build process and the availability of your private API, you may need to make other adjustments accordingly.

- If your private API is only available within your company network, then you would need to expose the private API to your CI server that runs the build, else you would need to run the gatsby build in your own computer.
- You may also need to configure the endpoints of the API differently for development or production. Refer the [environment variables](/docs/environment-variables/) guide to learn how to do that.

4. To ensure your site does not show outdated data, you may want to setup an automated process to trigger the process to rebuild your site whenever the data is updated. For instance, if you host your site in Netlify, you can [make a request for its webhook to trigger a new build](https://www.netlify.com/docs/webhooks/).