Slide 1

Slide 1 text

ScanAPI Automated Integration Testing and Live Documentation for your API Camila Maia 1 EuroPython 2020

Slide 2

Slide 2 text

Motivation Everything started in a week which I as Firefighter 2

Slide 3

Slide 3 text

I work at... 3

Slide 4

Slide 4 text

Who am I? 4 - Brazilian Backend Developer - Bachelor of Computer Information System - Coding since 2010 - Python and Ruby - Events: Pyjamas and EuroPython

Slide 5

Slide 5 text

Motivation Everything started in a week which I as Firefighter 5

Slide 6

Slide 6 text

Motivation Integration Errors 6 - Client sending fields different than what’s expected - Frontend receiving fields different than what’s expected

Slide 7

Slide 7 text

Motivation Outdated documentation 7 - Missing endpoints - Missing fields - Misinformation

Slide 8

Slide 8 text

Motivation Hard to recreate scenarios 8 /reserve/:seat_id flight_id? airplane_id? passenger_id? Is the airplane available? ????

Slide 9

Slide 9 text

Motivation Hard to recreate scenarios 9

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Proposal 11 - Open Source Framework - Written in Python 1. Provide a Live Documentation 2. Tool to implement integration tests

Slide 12

Slide 12 text

PokéAPI: https://pokeapi.co $ http https://pokeapi.co/api/v2/pokemon/ How does it work? Example: PokéAPI 12

Slide 13

Slide 13 text

13

Slide 14

Slide 14 text

14

Slide 15

Slide 15 text

How does it work? Example: PokéAPI 15 Installing: $ pip install scanapi

Slide 16

Slide 16 text

# api.yaml api: endpoints: - name: pokeapi path: https://pokeapi.co/api/v2/ endpoints: - name: pokemon path: pokemon requests: - name: list_all method: get path: / How does it work? Example: PokéAPI 16

Slide 17

Slide 17 text

How does it work? Example: PokéAPI 17 Running

Slide 18

Slide 18 text

How does it work? Documentation 18

Slide 19

Slide 19 text

19

Slide 20

Slide 20 text

20

Slide 21

Slide 21 text

21

Slide 22

Slide 22 text

How does it work? Integration tests ✅ 22 ... requests: - name: list_all method: get path: / tests: - name: status_code_is_200 assert: ${{ response.status_code == 200 }} - name: response_time_is_under_half_second assert: ${{ response.elapsed.total_seconds() < 0.5 }} https://requests.readthedocs.io - name: count_is_964 assert: ${{ response.json()["count"] == 964 }}

Slide 23

Slide 23 text

23

Slide 24

Slide 24 text

How does it work? Chaining Requests ⛓ 24 - Get details of a Pokémon - In this case, the data is “static”, but it might not be. - https://pokeapi.co/api/v2/pokemon/bulbasaur

Slide 25

Slide 25 text

How does it work? Chaining requests ⛓ 25 requests: - name: pokemon path: pokemon requests: - name: list_all method: get path: / vars: pokemon_name: ${{ response.json()["results"][0]["name"] }} tests: ... pokemon/${pokemon_name} - name: details method: get path: ${pokemon_name}

Slide 26

Slide 26 text

26

Slide 27

Slide 27 text

Adding ScanAPI to a project 27

Slide 28

Slide 28 text

Adding ScanAPI to a project 28

Slide 29

Slide 29 text

... scanapi: docker: - image: camilamaia/scanapi:1.0.5 steps: - checkout - run: name: Run ScanAPI command: | scanapi scanapi/api.yaml -c scanapi/.scanapi.yaml -o scanapi/report.html - store_artifacts: path: scanapi/report.html 29 - build-push: name: build-push-staging env: staging requires: - scanapi filters: branches: only: - master workflows: version: 2 main: jobs: - scanapi: filters: branches: only: - master

Slide 30

Slide 30 text

How does it work? And there is more 30 - Language-independent - It also accepts API spec in JSON - Environment variables - Hide sensitive info in the report - Multiple files API specification - Custom templates

Slide 31

Slide 31 text

Can I start using it? For sure! 31

Slide 32

Slide 32 text

scanapi.dev 32

Slide 33

Slide 33 text

Next Steps What about the future? 33 - Missing HTTP methods (current: GET, POST, PUT, PATCH, DELETE) - JSON visualization - Docs + Tutorials - Website improvements - GitHub Action And what if…. - OpenAPI

Slide 34

Slide 34 text

Why to contribute? Join us! 34 - Backend, frontend, automation, design - “Pure Python” - Understand how a lib works - Test coverage > 90% - Issues with labels - i.e: good first issue

Slide 35

Slide 35 text

Why to contribute? Join us! 35 How Open Source Changed My Life with Max Stoiber

Slide 36

Slide 36 text

Sprint Session 36 - Sprint session on this weekend - July 25th and 26th (free!) #sprint-scanapi More information

Slide 37

Slide 37 text

github.com/scanapi ⭐ 37

Slide 38

Slide 38 text

We are hiring! Loadsmart 38 Direct Link

Slide 39

Slide 39 text

THANK YOU @cmaiacd camilamaia #talk-scanapi #sprint-scanapi