You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/1-introduction-to-apis/3-different-paradigms.adoc
+7-8Lines changed: 7 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,8 @@
1
-
[#theory-paradigms]
2
1
= Understanding Different Paradigms
3
2
4
3
If APIs are the interface for some sort of service, it should not come as a surprise that not all the interfaces in the world are going to have the same needs and requirements. Most of them are a case of "execute a command", "interact with data", or a combination of both.
5
4
6
-
There are three distinct types of Web API which handles these common needs, and these different types are known as paradigms. To oversimplify things a bit, it’s reasonably fair to say that all APIs conform to one of these paradigms:
5
+
There are three distinct types of Web API which handles these common needs, and these different types are known as paradigms. To oversimplify things a bit, it's reasonably fair to say that all APIs conform to one of these paradigms:
7
6
8
7
- RPC (Remote Procedure Call)
9
8
- REST (Representational State Transfer)
@@ -13,7 +12,7 @@ These paradigms are general approaches to building APIs, not a specific tool or
13
12
14
13
*Implementations* are something you can actually download, install, and use to build an API, that conforms to whatever rules the implementors picked, from whichever paradigm (or paradigms) they were interested in at the time.
15
14
16
-
*Specifications* (or standards, recommendations, etc.) are often drafted up by various working groups, to help implementations share functionality in the same way. An API and a client in different languages can work together perfectly if they’re all following the specification correctly. The difference between a standard and a specification is usually just down to who made it. When a working group like the IETF or W3C create something, it's a standard, but when Google knock something out on their own, it's a specification.
15
+
*Specifications* (or standards, recommendations, etc.) are often drafted up by various working groups, to help implementations share functionality in the same way. An API and a client in different languages can work together perfectly if they're all following the specification correctly. The difference between a standard and a specification is usually just down to who made it. When a working group like the IETF or W3C create something, it's a standard, but when Google knock something out on their own, it's a specification.
17
16
18
17
For example:
19
18
@@ -126,15 +125,15 @@ REST, however, presents you with the next available options:
126
125
127
126
*Client:* Hi, I would like to speak to Dr Watson, is he there?
128
127
129
-
*REST:* Doctor Watson is not currently in the office, he’ll be back tomorrow, but you have a few options. If it’s not urgent you could leave a message and I’ll get it to him tomorrow, or I can book you with another doctor, would you like to hear who is available today?
128
+
*REST:* Doctor Watson is not currently in the office, he'll be back tomorrow, but you have a few options. If it's not urgent you could leave a message and I'll get it to him tomorrow, or I can book you with another doctor, would you like to hear who is available today?
130
129
131
130
*Client:* Yes, please let me know who is there!
132
131
133
132
*REST:* Doctors Smith and Jones, here are links to their profiles.
134
133
135
-
*Client:* Ok, Doctor Jones looks like my sort of Doctor, I would like to see them, let’s make that appointment.
134
+
*Client:* Ok, Doctor Jones looks like my sort of Doctor, I would like to see them, let's make that appointment.
136
135
137
-
*REST:* Appointment created, here’s a link to the appointment details.
136
+
*REST:* Appointment created, here's a link to the appointment details.
138
137
139
138
REST provided all of the relevant information with the response, and the client was able to pick through the options to resolve the situation.
140
139
@@ -146,7 +145,7 @@ This book will get more in-depth on hypermedia controls later. There are a few o
146
145
147
146
- REST must be stateless: not persisting sessions between requests
148
147
- Responses should declare cacheablility: helps your API scale if clients respect the rules
149
-
- REST focuses on uniformity: if you’re using HTTP you should utilize HTTP features whenever possible, instead of inventing conventions
148
+
- REST focuses on uniformity: if you're using HTTP you should utilize HTTP features whenever possible, instead of inventing conventions
150
149
151
150
These constraints of REST when applied to HTTP APIs can help the API last for decades, which is a whole lot more complex without these concepts. What does that mean? Well, REST is often described as a series of layers of abstraction on top of RPC, with all relevant instructions related to the handling of that message being baked into the message itself, to avoid having to tell a human about specific ways to handle things. As things change throughout the entire ecosystem, a well trained REST API and client should be able to handle those changes seamlessly, because the REST API is describing itself well and the client is listening. This loosens the coupling found in other paradigms, where a lot of that is baked into the client itself.
152
151
@@ -236,7 +235,7 @@ All of this has the advertised benefit of making GraphQL portable enough that it
236
235
237
236
GraphQL has many fantastic features and benefits, which are all bundled in one package, with a nice marketing site. If you are trying to learn how to make calls to a GraphQL API, the http://graphql.org/learn/[Learn GraphQL] documentation will help, and their site has a bunch of other resources.
238
237
239
-
Seeing as GraphQL was built by Facebook, who had previously built a REST__ish__ API, they’re familiar with various REST/HTTP API concepts. Many of those existing concepts were used as inspiration for GraphQL functionality, or carbon copied straight into GraphQL.
238
+
Seeing as GraphQL was built by Facebook, who had previously built a REST__ish__ API, they're familiar with various REST/HTTP API concepts. Many of those existing concepts were used as inspiration for GraphQL functionality, or carbon copied straight into GraphQL.
240
239
241
240
The main selling point of GraphQL is that it defaults to providing the very smallest response from an API, as you are requesting only the specific bits of data that you want, which minimizes the Content Download portion of the HTTP request.
servers, and it does this by taking a URL to a server for comparison. This could
445
-
be staging, pre-production, or even production if you're careful.
434
+
Microcks handles contract testing as well as mock servers, and it does this by
435
+
taking a URL to a server for comparison. This could be staging, pre-production,
436
+
or even production if you're careful.
446
437
447
438
It works by going through all the operations in the OpenAPI document, and uses
448
439
the examples and schemas defined there to send a request that should work, to an
@@ -490,7 +481,7 @@ jobs:
490
481
waitFor: '10sec'
491
482
----
492
483
493
-
_Learn more about xref:_guides/bump-sh-tutorials/testing-with-microcks.adoc[contract testing with Microcks]._
484
+
_Learn more about https://docs.bump.sh/guides/bump-sh-tutorials/testing-with-microcks/[contract testing with Microcks]._
494
485
495
486
== Phase 3: Deploying Artifacts
496
487
@@ -584,7 +575,7 @@ workflow like this for clarity. Either way, whenever a change is made to the
584
575
`main` branch the mock servers will be updated and instantly reflect the latest
585
576
OpenAPI.
586
577
587
-
_Learn more about xref:_guides/bump-sh-tutorials/mocking-with-microcks.adoc[API mocking with Microcks]._
578
+
_Learn more about https://docs.bump.sh/guides/bump-sh-tutorials/mocking-with-microcks/[API mocking with Microcks]._
588
579
589
580
=== Publish SDKs
590
581
@@ -601,8 +592,8 @@ over HTTP directly.
601
592
SDK generation tools have been around for a long time, but in the past the best
602
593
offering was a cumbersome Java-based open-source tool where you generally had to
603
594
develop your own templates. Modern tooling like
604
-
xref:_guides/bump-sh-tutorials/generate-sdks-with-speakeasy.adoc[Speakeasy] and
605
-
xref:_guides/bump-sh-tutorials/stainless-integration.adoc[Stainless] allow API
595
+
https://www.speakeasy.com/[Speakeasy] and
596
+
https://www.stainless.com/[Stainless] allow API
606
597
providers to point to an OpenAPI document, and produce type-safe SDKs that your
607
598
team will be proud of. These will handle tricky functionality like OAuth 2,
608
599
retries, pagination, and even allow for adding custom code to the generated
@@ -650,8 +641,6 @@ or rudimentary code samples like using `fetch()` or other low-level HTTP code.
650
641
651
642
image::images/bump-sdks.png[The Train Travel API documentation example on Bump.sh with a TypeScript SDK generated by Speakeasy showing in the documentation.]
652
643
653
-
_Learn more about xref:_guides/bump-sh-tutorials/generate-sdks-with-speakeasy.adoc[SDK generation with Speakeasy]._
654
-
655
644
=== API Catalog
656
645
657
646
Another key part of API governance is discoverability, which usually takes the
@@ -666,7 +655,12 @@ Alternatively, Hubs could be used to group APIs by team or department.
666
655
667
656
image::images/bump-hubs.png[A list of APIs, descriptions, and last updated times, for a sample Hub on Bump.sh]
668
657
669
-
_Learn more about xref:_guides/bump-sh-tutorials/api-discovery-using-bump-sh-hubs.adoc[API discovery with Bump.sh Hubs]._
658
+
Making sure API catalogs are up to date and contain 100% of APIs can be tricky,
659
+
but there are various ways to do it. One could be using an API Gateway that also
660
+
happens to support API catalogs like [Kong
661
+
Gateway](https://konghq.com/products/kong-gateway) and the [Service
0 commit comments