27
APIs

Apis and-web-programming

Embed Size (px)

DESCRIPTION

A primer on building blocks of the web and our GoCardless API

Citation preview

Page 1: Apis and-web-programming

APIs

Page 2: Apis and-web-programming

Stuff to cover

• What is an API?

• What is HTTP?

• What is REST mean and why is it good?

• How the connect flow works for a simple integration?

• How the connect flow works for a partner integration?

• How do webhooks work?

Page 3: Apis and-web-programming

What is an API• Application Programming Interface

• A set of instructions for communicating with an application

• Normally refer to web based services but all sorts of software can have an API

Page 4: Apis and-web-programming

• startToasting();

• “OK Begun Toasting”

• stopToasting();

• “OK Toasting ended”

• isToasting();

• TRUE

• FALSE

Dualit API v1

Page 5: Apis and-web-programming

What is HTTP?• How we transfer Hypertext (i.e. HTML)

• Unencrypted unless using HTTPS

• Everything on GoCardless is forced over HTTPS by Google Chrome

• Information is transferred with a verb:

• HTTP verbs suggest context of actions

Page 6: Apis and-web-programming

GET PUT

POST DELETE

Get Update Create Delete

HTTP VERBS (What they actually mean)

Page 7: Apis and-web-programming

Demo

Page 8: Apis and-web-programming

What is REST?• Representational state transfer

• Basically, a set of guidelines that together make an API that could be described as “RESTful”

• An API is RESTful if it:

• Uses standard HTTP verbs (PUT, GET, POST)

• Has one base URI (api.gocardless.com)

• Uses standard internet media JSON or XML

• Hypertext links to related resources

• REST v SOAP

Page 9: Apis and-web-programming

• Has one base URI (gocardless.com)

• Uses standard internet media JSON or XML

• Uses standard HTTP methods (PUT, GET, POST)

• Hypertext links to related resources

API endpoint for creating a customer

Page 10: Apis and-web-programming

What is SOAP?

• Simple Object Access Protocol

• XML messages, harder to process (and read) than JSON

• Security built in to SOAP messages, doesn’t rely on HTTPS

Page 11: Apis and-web-programming

Why is REST good?

• Because it’s a standard, predictability of code writing speeds up development time

• Helps you organise a complex system into simple resources (Payment, Customer)

• Security is handled independently by transport layer (HTTPS)

• Simpler, more human readable than SOAP messages

Page 12: Apis and-web-programming

• Something more dynamic than a paylink

• Imagine we’re a charity and want the user to type in the amount they wish to donate on our website

• We want to let them select a one off or recurring payment for an amount they choose

A simple integration

Page 13: Apis and-web-programming

I wish to donate

£500|

Donate

Every month

Page 14: Apis and-web-programming
Page 15: Apis and-web-programming

Partner Connect Flow• Allow a partner to collect payments on behalf of their

merchants

• Examples: FreeAgent, Kashflow, Crowdfunding websites

Page 16: Apis and-web-programming

Merchant

💼Partner

👤

FreeAgent (partner) wants to allow Jim’s Gym (merchant) to take payments through GoCardless

Page 17: Apis and-web-programming

Merchant

💼Partner

👤

The merchant wants to be able to take payments through the partner

Page 18: Apis and-web-programming

Merchant

💼Partner

👤

The partner redirects the merchant to GoCardless

Page 19: Apis and-web-programming

Merchant

👤

The merchant needs to have an existing GoCardless account, or create a new one

Page 20: Apis and-web-programming

GoCardless asks the merchant to authorise the partner access to their account

Merchant

👤

Page 21: Apis and-web-programming

When the merchant authorises, GoCardless gives the partner a unique access token to store for future requests

💼Partner

NX8LSkRUIYVNZ1eFCBnh

Page 22: Apis and-web-programming

It failed

NX8LSkRUIYVNZ1eFCBnh

payment: failed

💼👤

Now, when the partner needs information from GoCardless about the merchant account, they send the access token each time

Whats the payment status?

Page 23: Apis and-web-programming

Partner flow demo

Page 24: Apis and-web-programming

Webhooks• Notification of events pushed from GoCardless to a third

party web service

• Typically this will be payment failures, new customers etc

💼“Payment failed”

Page 25: Apis and-web-programming

Webhooks• Webhooks allow us to instantly notify an API integration of an

event to do with their payments

• Merchants have to configure their app to “listen” to webhooks

Page 26: Apis and-web-programming

Webhook demo

Page 27: Apis and-web-programming

Questions?