Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Powering an API with GraphQL, Golang, and NoSQL

27 views

Published on

Learn how to build a GraphQL API, an alternative to REST, with the Go programming language and Couchbase as the NoSQL database.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Powering an API with GraphQL, Golang, and NoSQL

  1. 1. Powering an API with GraphQL, Golang, and NoSQL Nic Raboy Senior Developer Evangelist at HERE Technologies
  2. 2. The RESTful API
  3. 3. RESTful API
  4. 4. RESTful API with Multiple Related Endpoints
  5. 5. RESTful API Nothing’s wrong with RESTful APIs, but they could be better!
  6. 6. RESTful API • Too many API endpoints to remember • Too many API endpoints to maintain • Too much data to process • Too large of data payloads
  7. 7. The GraphQL API
  8. 8. The Benefits of GraphQL graphql.org graphql.org
  9. 9. GraphQL
  10. 10. GraphQL
  11. 11. GraphQL • Server to client payloads are flexible • Client to server queries are flexible • Minimal API endpoints to remember
  12. 12. Processing GraphQL in Go
  13. 13. GraphQL
  14. 14. GraphQL Data Model
  15. 15. GraphQL Query
  16. 16. GraphQL Query
  17. 17. GraphQL Query
  18. 18. GraphQL Endpoint
  19. 19. GraphQL cURL Request
  20. 20. Integrating a NoSQL Database
  21. 21. Couchbase: The Complete Database Solution Infographic provided by Couchbase
  22. 22. 22 Couchbase Lite Overview • Cross-platform support for all major operating systems and platforms • Built native from the ground up • 500kb for most platforms • 256-bit AES full database encryption Infographic provided by Couchbase
  23. 23. 23 Couchbase Server Overview • Scale easily to thousands of nodes • Consistent high performance that supports millions of concurrent users • Flexible JSON data model • 24x365 always-on availability Infographic provided by Couchbase
  24. 24. 24 Couchbase Sync Gateway Overview • Synchronize data between Couchbase Lite and Couchbase Server • REST, Stream, Batch, and Event APIs • Pluggable authentication • Fine grained user and role based access control • Elastically scalable in real-time Infographic provided by Couchbase
  25. 25. The Power of the Flexible JSON Schema • Ability to store data in multiple ways • De-normalized single document, as opposed to normalizing data across multiple table • Dynamic Schema to add new values when needed Infographic provided by Couchbase
  26. 26. Couchbase
  27. 27. Couchbase
  28. 28. Couchbase
  29. 29. What is N1QL? • Non-first (N1) Normal Form Query Language (QL) • It is based on ANSI 92 SQL • Its query engine is optimized for modern, highly parallel multi-core execution • SQL-like Query Language • Expressive, familiar, and feature-rich language for querying, transforming, and manipulating JSON data • N1QL extends SQL to handle data that is: • Nested: Contains nested objects, arrays • Heterogeneous: Schema-optional, non-uniform • Distributed: Partitioned across a cluster
  30. 30. N1QL (Expressive) • Access to every part of JSON document • Scalar & Aggregate functions • Subqueries in the FROM clause • Aggregation on arrays Expressive, familiar, and feature-rich language for querying, transforming, and manipulating JSON data
  31. 31. N1QL (Familiar) • SELECT * FROM bucket WHERE … • INSERT single & multiple documents • UPDATE any part of JSON document & use complex filter • DELETE • MERGE two sets of documents using traditional MERGE statement • EXPLAIN to understand the query plan • EXPLAIN SELECT * FROM bucket WHERE … Expressive, familiar, and feature-rich language for querying, transforming, and manipulating JSON data
  32. 32. N1QL (Feature-Rich) • Access to every part of JSON document • Functions (Date, Pattern, Array, Conditional, etc) • https://developer.couchbase.com/documentation/server/current/n1ql/n1ql-language-reference/functions.html • JOIN, NEST, UNNEST • Covering Index • Prepared Statements • USE KEYS, LIKE Expressive, familiar, and feature-rich language for querying, transforming, and manipulating JSON data
  33. 33. Couchbase
  34. 34. Couchbase with Go
  35. 35. Couchbase with Go
  36. 36. Couchbase with Go
  37. 37. Couchbase with Go
  38. 38. Couchbase with Go
  39. 39. GraphQL Mutations
  40. 40. GraphQL Data Mutations
  41. 41. GraphQL Data Mutations
  42. 42. GraphQL Data Mutations
  43. 43. Closing Thoughts
  44. 44. Summary • GraphQL limits the response payload • GraphQL offers flexibility in API responses • GraphQL cuts down the API endpoints • GraphQL is not a substitute for backend management • Couchbase is flexible with JSON • Couchbase is powerful with N1QL queries
  45. 45. Getting Help • GraphQL - graphql.org • Couchbase - couchbase.com • Twitter - @nraboy • Blog - thepolyglotdeveloper.com
  46. 46. THANK YOU

×