OpenAPI for Web Developers

A presentation at PHPUK 2025 in February 2025 in London, UK by Lorna Jane Mitchell

Slide 1

Slide 1

OpenAPI for Web Developers Lorna Mitchell @lornajane@indieweb.social

Slide 2

Slide 2

About OpenAPI Standard for describing APIs, for machines and for humans. @lornajane@indieweb.social

Slide 3

Slide 3

OpenAPI Example openapi: 3.0.1 servers: - url: http://datasette.local - url: https://datasette.io info: description: Execute SQL queries against a Datasette database and return the results as JSON title: Datasette API version: v1 paths: /content.json: get: description: Accepts SQLite SQL query, returns JSON. Does not allow PRAGMA statements. Credit: https://github.com/APIs-guru/openapi-directory @lornajane@indieweb.social

Slide 4

Slide 4

Code-First vs Design-First @lornajane@indieweb.social

Slide 5

Slide 5

If you wrote the API code already Get an OpenAPI file of what you have, and then start using it design-first. Two great options: •generate from your codebase •use a learning/sniffing tool like Optic @lornajane@indieweb.social

Slide 6

Slide 6

If you wrote the API code already @lornajane@indieweb.social

Slide 7

Slide 7

If you have humans using your API Make the OpenAPI human-readable with docs! •Scalar (next-generation docs) •Redoc (traditional docs) •Bump.sh (short-lived hosted docs) @lornajane@indieweb.social

Slide 8

Slide 8

If you have humans using your API @lornajane@indieweb.social

Slide 9

Slide 9

If your OpenAPI needs editing Designed OpenAPIs can be edited safely But generated ones do have options. •OpenAPI Overlay Specification is a standard for describing edits •Speakeasy and Bump.sh have good Overlay tools •Look out for other transformation tools @lornajane@indieweb.social

Slide 10

Slide 10

Repeatably edit an OpenAPI Part 1 is to prepare the Overlay: •Copy the the OpenAPI file, and edit the copy •Use speakeasy compare creates a diff as an Overlay •Web GUI: https://overlay.speakeasy.com Part 2 is to apply it in every build, locally and in CI •Try the bump or speakeasy CLI tools. @lornajane@indieweb.social

Slide 11

Slide 11

Repeatably edit an OpenAPI @lornajane@indieweb.social

Slide 12

Slide 12

If you have code using your API @lornajane@indieweb.social

Slide 13

Slide 13

If you like API quality and consistency API standards are a document. Use linting to check: •plurals and casing •every operation has an ID •everything named *-date uses the expected format •errors are defined and in the expected format Try: Spectral or Vacuum. @lornajane@indieweb.social

Slide 14

Slide 14

If an API sandbox would be useful Use an API Mock Server tool. Tools include: Microcks, Prism @lornajane@indieweb.social

Slide 15

Slide 15

If an API sandbox would be useful @lornajane@indieweb.social

Slide 16

Slide 16

To avoid API drift Contract testing is your friend! Check that what the API does matches what is described. Tools include: Microcks, WireMock, Pact @lornajane@indieweb.social

Slide 17

Slide 17

To avoid API drift @lornajane@indieweb.social

Slide 18

Slide 18

API Description Pipelines OpenAPI isn’t a static asset. @lornajane@indieweb.social

Slide 19

Slide 19

OpenAPI Community @lornajane@indieweb.social

Slide 20

Slide 20

OpenAPI Community •Part of the Linux Foundation •Standard is developed in the open •https://openapis.org •Public GitHub repository •Active Slack groups •Weekly technical meetings @lornajane@indieweb.social

Slide 21

Slide 21

OpenAPI Standards •Overlays map repeatable amendments to an OpenAPI file (v1.0.0) •Arazzo describe a sequence of API calls (v1.0.1) •OpenAPI describes your API for all the tools to use •stable: 3.1.1 •planned: 3.2.0 •early days: 4.0 “Moonwalk” @lornajane@indieweb.social

Slide 22

Slide 22

OpenAPI Open standard for API descriptions @lornajane@indieweb.social

Slide 23

Slide 23

Resources •https://lornajane.net •https://openapis.org •https://github.com/opticdev/optic •https://speakeasy.com •https://bump.sh •https://microcks.io/ •https://apisyouwonthate.com/ @lornajane@indieweb.social