/api

Introduction to API and API testing. Automating workflow using Insomnia and GitHub Actions

Some images not showing? Try refreshing window, often case when README's partially load image elements

API course playground repo

Special thanks to @bearc0025 for introduction to API world!

Local API Server Setup

  • Download node binary 64 bit - https://nodejs.org/en/download/
  • add ENV variables:
    • NPM_HOME - C:\node-16.16.0
    • NODE_EXTRA_CA_CERTS - C:\Users\XXXX\ .certs\XXXCA_Certs.pem
  • might need to update npm version - npm install -g npm@8.19.1
  • Install JSON server - npm install -g json-server
  • Confirm JSON server is downloaded - npm list -g json-server (`-- json-server@0.17.0)
  • Run local api server - npx json-server -w db.json

  \{^_^}/ hi!

  Loading db.json
  Done

  Resources
  http://localhost:3000/users
  http://localhost:3000/attempts

  Home
  http://localhost:3000

  Type s + enter at any time to create a snapshot of the database
  Watching...

Data can be accessed via Home link Local Server

Insomnia x GitHub Actions Setup

(Insomnia)

  • Settings > uncheck Enable proxy
  • Sync With GitHub
  • Add + enter password -> copy the URL to Insomnia + Add
  • or Add via Git, but you need to create Access Token

Sync OK

Run Insomnia cli commands

Insomnia dashboard name (IDN) - "MyAPI" (spc_a1f2a2) Insomnia test env name (ITEN) - "OpenAPI" (env_env_7032d2)

  • run tests
    • npx inso run test
    • npx inso run test IDN
    • npx inso run test IDN --env "env_env_7032d2"

Run tests

  • lint spec:
    • npx inso lint spec
    • npx inso lint spec "MyAPI"
    • npx inso lint spec spc_a1f2a2

Lint spec

Setup Github Actions

Make Insomnia init commit

  • Insomnia > main > Commit > select all resources > add description > commit
  • Insomnia > main > push
  • in GitHub .insomnia/ will be added

Test Github Actions

References

Note

  • When working:
    • disconnect from VPN
    • uncheck proxy settings in Insomnia
    • disable .npmrc proxy and registry parameters
  • Pull in Insomnia before every local commit to keep in sync!

Testing

Common errors

Error: getaddrinfo ENOTFOUND github.com
    at __node_internal_captureLargerStackTrace (node:internal/errors:464:5)
    at __node_internal_ (node:internal/errors:686:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26)
  • Internet connection is gone, re-connect to the internet