Skip to content

Latest commit

 

History

History

api_http_requests

Collection of API HTTP request samples

This folder contains a set of .http files that can be used to test the API

Running the requests in VS Code

  1. Install the Rest Client Extension

  2. In settings.json - add a section with environment variables that will be used for the requests

        "rest-client.environmentVariables": {
            "$shared": {
                "baseUrl": "http://localhost:8000/api",
                "contentType": "application/json",
                "workspaceTemplate": "my-tre-workspace",
                "workspaceServiceTemplate": "my-tre-workspace-service",
                "userResourceTemplate": "my-tre-user-resource",
                "workspaceId": "49ab7315-49bb-48ed-b9ca-c37369f15e7a",
                "workspaceServiceId": "2a3165e7-5b5c-40e5-b3b6-94f528e9fcf0",
                "userResourceId": "726e00b5-9408-4d81-a913-d890b4851307",
                "appId": "9d52b04f-89cf-47b4-868a-e12be7133b36",
                "token": "[TOKEN FROM SWAGGER UI]"
            },
        },

    Note: If you prefer, you can add environment specific variables (instead of adding all to $shared, but then you have to change environment in the bottom right bar in VS code when running the HTTP requests)

  3. Start the API locally - or modify the baseURL to point to an API running on Azure

  4. Authenticate with the API in Swagger and make a GET request to retrieve the authentication token (Bearer) - and modify the token variable in settings

  5. Run the requests in the HTTP files by clicking on send request above each request

Running the requests using PyCharms Rest-client

PyCharm has a built in rest client that allows us to run all requests in a .http file.

  1. Modify the variables defined in the http-client.env.json file to suit your needs

  2. Add a file called http-client.private.env.json to the API requests folder with the following contents

    {
        "dev": {
            "token": "[TOKEN FROM SWAGGER UI]"
        }
    }
  3. Start the API locally or modify the baseUrl in http-client.env.json to reflect the address of the API you are testing against

  4. Make a GET request in Swagger and update the token to your authentication token (Bearer)

  5. Run the requests