Interacting with Gcore API Using JetBrains HTTP Client
Tags: guide, solution
Published: 2023-06-22 11:29:28

Testing API requests is an essential aspect of developing and maintaining a RESTful API. Testing requests for your RESTful API is crucial for ensuring its functionality, reliability, performance, and adherence to specifications. It helps in identifying and addressing issues early in the development process, leading to a more stable and robust API that delivers the expected results to its consumers. In this blog, we’ll guide you through using the JetBrains HTTP client to interact with Gcore’s API, enhancing your development workflow through greater efficiency.

## Why Use JetBrains HTTP Client?

If you're looking for an efficient way to test your REST APIs or send HTTP requests, JetBrains HTTP client is an excellent option. The JetBrains HTTP client is an integrated tool available within JetBrains IDEs like IntelliJ IDEA, PyCharm, and WebStorm. It facilitates the testing, debugging, and analysis of RESTful APIs by allowing developers to create, execute, and inspect HTTP requests directly from their IDEs. With features like request creation, request history, response inspection, syntax highlighting, code snippet generation, variable substitution, test scripts, and authentication support, the JetBrains HTTP client provides a convenient and efficient way for developers to interact with APIs during development and testing. It enhances the development workflow by eliminating the need for external tools and ensuring seamless integration within the IDE environment.

## Step 1: Install the JetBrains HTTP Client

To start using the JetBrains HTTP client, first install it in your IDE. The HTTP client is built into JetBrains IntelliJ IDEA, PhpStorm, WebStorm, and PyCharm, so you don’t need to install anything extra.


## Step 2: Create a New HTTP Request File

After installing the JetBrains HTTP client, open your IDE and create a new file by selecting **File → New → HTTP Request**. Here’s an example of a health check API provided by Gcore:

```
### HEALTH CHECK

GET https://api.gcore.com/dns/healthcheck
```

A health check API is an endpoint that provides information about the health and status of an application or service. It allows you to assess programmatically the availability and readiness of critical components and determine if your application is functioning properly.

Health check APIs are commonly used in conjunction with monitoring and alerting systems to proactively detect issues and ensure system reliability. They are especially useful in distributed and microservices architectures, and are often integrated with containerization or orchestration systems.

## Step 3: Add Request Headers

Request headers contain additional information about the request, such as the type of data being sent or authentication credentials. To add headers, click the **Headers** tab in the request window and provide the required information. Some of Gcore’s API requires an authorization header. Here’s an example of the GET zone API that requires a header:

```
### GET ZONE

GET https://api.gcore.com/dns/v2/zones?limit=10
Authorization: Bearer REPLACE_WITH_YOUR_TOKEN
```

## Step 4: Add Request Body

If you need to send data with your request, you can add it to the request body. Click the **Body** tab, choose the type of data you want to send (JSON, XML, etc.,) and enter your data in the editor. Here’s an example of an API request to create a new zone on Gcore:

```
### CREATE ZONE

POST https://api.gcore.com/v2/zones
Authorization: Bearer REPLACE_WITH_YOUR_TOKEN
Content-Type: application/json

{
  "name": "one.gcdn.co",
  "primary_server": "ns1.example.com",
  "serial": 1,
  "nx_ttl": 1
}
```

## Step 5: Send the Request

Once you have completed the request configuration, click **Run** to send the request. To see the response, check the Response tab, which shows the response status code, headers, and body.

```
GET https://api.gcore.com/dns/healthcheck

HTTP/1.1 200 OK
Server: nginx
Date: Tue, 20 Jun 2023 07:32:04 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 124
Connection: keep-alive
Content-Encoding: deflate
Vary: Accept-Encoding
Strict-Transport-Security: max-age=15724800; includeSubDomains
Cache: MISS
X-ID: ed-up-gc38
X-NGINX: nginx-be
Accept-Ranges: bytes
X-ID-FE: ed-up-gc38

{
  "app": "gcdn-dns-api",
  "hash": "0b5371a",
  "postgres_ping_success": true,
  "uptime": "191h39m45.146275442s",
  "uptime_seconds": 689985,
  "version": "0b5371a"
}

Response file saved.
> 2023-06-20T143205.200.json

Response code: 200 (OK); Time: 790ms (790 ms); Content length: 145 bytes (145 B)
```

## Conclusion

JetBrains HTTP client is a useful tool for testing REST APIs and making HTTP requests. It is easy-to-use, informative, convenient for everyday usage. By following the steps outlined in this tutorial, you can easily use JetBrains HTTP client to test your APIs and analyze responses. [Check out Gcore’s API docs](https://apidocs.gcore.com/dns#tag/zones) to learn more.