Upgrade to Pro — share decks privately, control downloads, hide ads and more …

APIOps

 APIOps

Daniel Kocot

March 21, 2022
Tweet

More Decks by Daniel Kocot

Other Decks in Technology

Transcript

  1. Name: Daniel Kocot Role: Senior Solution Architect / Head of

    API Experience & Operations Email: Twitter: @dk_1977 LinkedIn: [email protected] https://www.linkedin.com/in/danielkocot/
  2. API first An API is the first (and often only)

    interface to users of an application An API comes first — before the implementation An API is described (documented) or self-descriptive
  3. GIT some kind of GitFlow no direct commits to main

    Branch every change to specification and the pipeline has to be a pull request
  4. Spectral > npm install -D @stoplight/spectral > npx spectral lint

    news.yaml OpenAPI 3.x detected No results with a severity of 'error' or higher found!
  5. Ruleset formats: - oas3.0 extends: - 'spectral:oas' rules: tags-have-description: description:

    Tags must have a description. message: Description of Tag is missing given: $.tags[*] recommended: true type: style then: field: description function: truthy
  6. Prism > npm install -D @stoplight/prism-cli > npx prism mock

    news.yaml -p 8080 [17:13:00] › [CLI] … awaiting Starting Prism… [17:13:01] › [CLI] ℹ info GET http://127.0.0.1:8080/news [17:13:01] › [CLI] ▶ start Prism is listening on http://127.0.0.1:8080
  7. Unit testing Create a test suite based directly on the

    spec Using a BDD framework Create a test suite based on a postman collection
  8. Portman ================================================================= Local Path: specs/news.yaml Portman Config: portman-config.default.json Postman Config:

    postman-config.default.json Environment: .env Inject Tests: true Run Newman: true Newman Iteration Data: false Upload to Postman: false ================================================================= ✔ Conversion successful ================================================================= Run Newman against: ================================================================= newman News API ❏ news ↳ get News GET http://localhost:8080/news [200 OK, 384B, 85ms] ✓ [GET]::/news - Status code is 2xx ✓ [GET]::/news - Content-Type is application/json ✓ [GET]::/news - Response has JSON Body
  9. postman-to-k6 > npm install -D postman-to-k6 > mkdir k6 >

    npx postman-to-k6 post-collections/news-postman-collection.json -o k6/news-k6-script.js
  10. k6 /\ |‾‾| /‾‾/ /‾‾/ /\ / \ | |/

    / / / / \/ \ | ( / ‾‾\ / \ | |\ \ | (‾) | / __________ \ |__| \__\ \_____/ .io execution: local script: k6/news-k6-script.js output: - scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop): * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s) running (00m00.0s), 0/1 VUs, 1 complete and 0 interrupted iterations default ✓ [======================================] 1 VUs 00m00.0s/10m0s 1/1 iters, 1 per VU data_received..............: 502 B 26 kB/s data_sent..................: 134 B 7.0 kB/s http_req_blocked...........: avg=1.31ms min=1.31ms med=1.31ms max=1.31ms p(90)=1.31ms p(95 http_req_connecting........: avg=237µs min=237µs med=237µs max=237µs p(90)=237µs p(95 http_req_duration..........: avg=12.92ms min=12.92ms med=12.92ms max=12.92ms p(90)=12.92ms p(95 http_req_failed............: 100.00% ✓ 1 ✗ 0 http req receiving : avg=110µs min=110µs med=110µs max=110µs p(90)=110µs p(95
  11. YAML / JSON YAML is more human-readable JSON is more

    machine-readable Parsing JSON is faster ;)
  12. Something is needed to rebundle the files to one >

    npx @redocly/openapi-cli > openapi bundle specs/news.yaml --output output/news.yaml
  13. Use of OpenAPI Extensions/X-Objects to handle own or vendor needs

    x-vendor-…​ x-…​ Supported by: root level info paths operation parameters responses tags security schemes
  14. From API description to configuration as code OpenAPI with Extensions

    AWS Cloudformation AWS CDK Azure ARM Templates Azure Bicep Pulumi
  15. Example AWS Cloudformation - API Spec openapi: 3.0.0 info: title:

    API Gateway OpenAPI Example version: 1.0.0 paths: /api/posts: get: summary: List Posts operationId: listPosts requestBody: required: true content: application/json: schema: '$ref': '#/components/schemas/CreatePostRequestBody' responses: '200': description: Retrieve the list of Posts content: application/json: schema: '$ref': '#/components/schemas/ListPostsResponseBody' x-amazon-apigateway-integration:
  16. Example AWS Cloudformation - S3 Bucket Stack AWSTemplateFormatVersion: 2010-09-09 Resources:

    ArtifactBucket: Type: AWS::S3::Bucket Outputs: ArtifactBucket: Description: The name of the artifact bucket Value: !Ref ArtifactBucket Export: Name: !Sub ${AWS::StackName}-artifact-bucket
  17. Example AWS Cloudformation - AWS API-Gateway Stack AWSTemplateFormatVersion: '2010-09-09' Parameters:

    ProjectId: Type: String Default: experiment Bucket: Type: String Default: api-gateway-openapi-artifact-bucke-artifactbucket-1wmq2pswrxwjw OpenAPIS3Key: Type: String Default: openapi.yaml Resources: Api: Type: AWS::ApiGateway::RestApi Properties: Name: !Ref AWS::StackName Description: 'An experimental API' FailOnWarnings: true
  18. Some gateways vendors have their own toolsets for CaC which

    have to be integrated in an existing toolchain For example: Kong decK Inso (Insomnia CLI) Tyk Tyk Sync
  19. Transformation to automation within CI/CD API first GIT Process Well

    structured and formed API specification Automated Validation Automated Testing Automated Deployment of revelant infrastructure
  20. Q&A

  21. References Photo on slide 7 by on Photo on slide

    13 by on Alice Dietrich Unsplash Danial Igdery Unsplash