Introduction

This guide will help you create a YAML configuration file for the Nubettix Mock API project. The configuration file defines the endpoints, methods, responses, and other settings for your mock API. We’ll use a pet API as an example, with three endpoints: one for retrieving pet information (GET), one for adding a new pet (POST), and one for deleting a pet (DELETE).

Note: all path params need to be like this /my_path/<query_param>, in this guide we need to use this format for only for the examples {query_param}

 

 

 

Steps to Create the YAML Configuration

Step 1: Define the Server Configuration

Start by defining the server configuration, including the port and base URL.


server:
  port: 4501
  base_url: "/v1"

Step 2: Define the Endpoints

Next, define the endpoints for your API. We’ll create three endpoints: /pets, /pets/{pet_id}, and /pets/{pet_id}.

Endpoint 1: Get Pet Information (GET)

This endpoint retrieves information about a specific pet.


endpoints:
  - path: "/pets/{pet_id}"
    method: "GET"
    path_params:
      - name: "pet_id"
        required: true
    response:
      200:
        body:
          id: "{pet_id}"
          name: "Fluffy"
          type: "Cat"
          age: 3
      404:
        body:
          error: "Pet not found"
    headers:
      - name: "Authorization"
        required: true

Endpoint 2: Add a New Pet (POST)

This endpoint adds a new pet to the database.


  - path: "/pets"
    method: "POST"
    response:
      201:
        body:
          id: "12345"
          name: "Fluffy"
          type: "Cat"
          age: 3
      400:
        body:
          error: "Invalid pet data"
    headers:
      - name: "Authorization"
        required: true
    query_params:
      - name: "notify"
        required: false

Endpoint 3: Delete a Pet (DELETE)

This endpoint deletes a specific pet from the database.


    - path: "/pets/{pet_id}"
    method: "DELETE"
    path_params:
      - name: "pet_id"
        required: true
    response:
      204:
        body: {}
      404:
        body:
          error: "Pet not found"
    headers:
      - name: "Authorization"
        required: true

Final configuration

remember the file configuration need this name:
api_config.yaml


 server:
  port: 4501
  base_url: "/v1"

endpoints:
  - path: "/pets/{pet_id}"
    method: "GET"
    path_params:
      - name: "pet_id"
        required: true
    response:
      200:
        body:
          id: "{pet_id}"
          name: "Fluffy"
          type: "Cat"
          age: 3
      404:
        body:
          error: "Pet not found"
    headers:
      - name: "Authorization"
        required: true

  - path: "/pets"
    method: "POST"
    response:
      201:
        body:
          id: "12345"
          name: "Fluffy"
          type: "Cat"
          age: 3
      400:
        body:
          error: "Invalid pet data"
    headers:
      - name: "Authorization"
        required: true
    query_params:
      - name: "notify"
        required: false

  - path: "/pets/{pet_id}"
    method: "DELETE"
    path_params:
      - name: "pet_id"
        required: true
    response:
      204:
        body: {}
      404:
        body:
          error: "Pet not found"
    headers:
      - name: "Authorization"
        required: true