# Method Operations

In this article, we will be discussing various HTTP methods. We will see how HTTP requests can be made through the *API Client* object in Astera.

For our use cases, we have made use of the *Petstore* Open-API definition. We can import the API to the *API Browser* using its import URL.

Once done, it automatically establishes various pre-defined endpoints as *API Client* objects. They can then be dragged and dropped onto a dataflow for further configurations and transformations.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/GfcnSUGky5Dyxuuj7Ves/11-Limit-Three.PNG)

{% hint style="info" %}
**Note:** When imported, a shared connection object will also be created containing the base URL and authentication details.
{% endhint %}

To learn more about importing a URL to the API Browser, click [here](https://documentation.astera.com/api-flow/api-consumption/consume/api-browser).

### Making a GET Request

1. First, drag-and-drop the *Get a file’s metadata or Content by ID* endpoint from the browser onto the Dataflow.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/YCwTdc5L1BljXD70i4Vt/02-Endpoint.PNG)

In this scenario, we want to get metadata for a file with *fileID*,

“184Gi7q9iPQyiR6lkG3bdSi5z3-9eeT-d”.

For this, we will pass the relevant *fileID* using a [*ConstantValue*](https://documentation.astera.com/dataflows/transformations/constant-value-transformation) object.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/4bIlDxtcHvyWlPJQrwoR/03-GET.PNG)

2. To explore the *API Client* object for this method, right-click on the object’s header and select *Properties.*

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/Bg0Po6ukNqT9cyvdPUkV/03-Prop.png)

This will open the *API Client* screen where the connection info of your API is defined.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/X44PGHZQ9gj9sSyduf02/04-Connection.PNG)

The *Shared Connection*, *Method*, and *Resource* here are already configured. Notice that *Resource* consists of ‘files’ along with the ‘fileid’ URL parameter.

![](https://docs.astera.com/projects/data-services/en/latest/_images/05-Define.PNG)

3. Click *Next*.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/idlDx9GICVd7lWznBJSM/06-Parameter.PNG)

Here, the ‘field’ URL parameter follows from the defined resource.

For our use case, we will use this parameter to get details for a pet.

Click *Next* to proceed to the *Output Layout* screen, where you can view the *Response Layout* of your API. There are two ways in which you can generate the output layout if required.

* The first one is by providing sample text by clicking the *Generate Layout by providing Sample Text* option.
* The other way to do this is by running a request by clicking the *Generate Layout by running Request* option.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/zRI3EPAEstfFAM1fpAcq/07-Output-Layout.PNG)

4. Click *Next* to proceed to the *Pagination Options* screen.

For our use case, we have selected *None.*

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/gRjrI1MR9dC42UvEmhAe/08-Pagination.PNG)

5. Click *OK*.
6. You can preview the data by right-clicking on the object and selecting *Preview Output* from the context menu.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/55QmSPJshqXjvgXTU7k8/09-Preview.PNG)

As seen below, the GET request that was made, has fetched data according to the user application.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/mvzovgAnmXY0tOmFzS8s/10-Data.PNG)

### Making a POST Request

Now, let’s try creating a new file.

1. Drag-and-drop the POST method as an *API Client* object and open its *properties*.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/GQqJgLo4GuBdC7uI94VS/11-Client.PNG)

We will pass the required parameters to the *POST request* object using a *Variables* object.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/NFF9eh6QkBtKpGYpjOPL/12-Post.PNG)

2. Now, right-click on the *API Client* object and select *Preview Output*.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/6O0u2bf38gZZ6GtactiF/13-Preview.PNG)

You can see that the *HTTPStatusCode* is “200”, which means that the API has successfully carried out the action requested by the client.

Let’s verify it by making a GET request for the same *FileId* that we had posted earlier.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/t7f0E2arLQ3hVqDyPcoP/14-Flow.PNG)

You can see that a GET request for *FileID* has returned the same information that we had posted.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/6twSN0IU4qwvPpPocLrm/15-Preview-Final.PNG)

### Making a DELETE Request

Now, let’s try making a DELETE request.

1. For this, we will first make a GET request to check whether that file exists in the records before we try to delete this record.

We will pass a *fileId* using a *ConstantValue* object.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/7FJzy0671oc0Kq3QZojs/16-Petstore.PNG)

2. Right-click on the *API Client* object and select *Preview Output*.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/ATbn8vrIKD5ezENA6AZK/17-PetID.PNG)

It has fetched the details of the file with the *fileId* and the status shows that the field is available.

To delete this file record, we will drag and drop another DELETE *API Client* object onto the flow and configure its *Properties* according to the DELETE method.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/Z6BXZdPf4VVjWAUlVl4X/18-Delete.PNG)

3. Pass the *fileId* to the DELETE *request* object using a *ConstantValue* object.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/bB4SS2UORxl1aEPwGqXM/19-01-Verify.PNG)

4. Right-click on the *API Client* object and select *Preview Output*. You can see that it has returned *HTTPStatusCode*, “204”, which indicates successful execution.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/mcWIBwpI8YL89v6iJOIh/19-Deleted-Success.PNG)

Let’s verify it by making a GET request again, and check if the *fileId*, has been deleted.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/9xWrhHS4ahoXjMw1tVuE/20-Verify.PNG)

5. Right-click on the *API Client* object and select *Preview Output.*

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/eUUGxsNVgboUsw25yLi0/25-DELETE-Preview-GET.PNG)

You can see that Astera has returned error 404 which means that there is no pet found with *PetId*, “5”, and the pet record has been successfully deleted from *petstore* API.

![](https://docs.astera.com/projects/data-services/en/latest/_images/21-404.PNG)

You can see that Astera has returned error 404 which means that there is no fileId found, and the file record has been successfully deleted from *Google Drive* API.

### Making a PUT Request

Let us now look at the PUT *HTTP Method*.

1. Drag-and-drop the *GET* endpoint from the API Browser onto the Dataflow.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/RadOrByUNl34RS4E50Iq/22-Get.PNG)

2. Right-click on the object and select *Properties* from the context menu.
3. Click *Next,* and the *Parameters* screen will appear.

For this use case, we will update the file with a *fileId*. Let’s define this ID in the *Default Value* field.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/kDbSoa9QSCot5OJPbuC8/23-File.PNG)

4. Click *OK* and preview the output by right-clicking on the object and selecting *Preview Output*

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/RFrWWrDD3rwipIyJdXdR/24-Preview.PNG)

As you can see in the preview screen below, the *GET* method has retrieved the file Metadata by ID.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/yVvX4O81cq3Ld0clL4VK/25-Retrieved.PNG)

5. Now, drag-and-drop the relevant endpoint from the API Browser onto the Dataflow.

For our use case, we will be using this *Patch* object for the *PUT* method so we can update the ID.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/1fUQzu6uD3ZdPh5tt0Q0/35-Put-Patch.PNG)

Right-click on the object and select *Properties* from the context menu.

Our *Shared Connection* has already been defined. The *HTTP Method* is *Put*, and the *Resource* to update is a file.

6. Click *Next*, and you will be led to the *Output Layout* screen

We have defined the *fileId* here that we wish the resource to be updated to,

If required, an output can be generated by running a request using the available option.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/l57FF5v2OxzLVXHvQTqk/36-Output-ID.PNG)

7. Click *OK*, right-click on the object, and select *Preview Output*.

As you can see here, the *fileId* has been updated,

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/es0o9RnNYIhnP5IFkVWt/38-Updated.PNG)

8. We will now preview the output of the *GET* object we have configured to verify if the pet status has been updated.

As you can see, the value has been updated.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/HgVh0FzrLcG3E0AXmEnB/39-GET-Verify.PNG)

### Making a PATCH Request

Let’s make a GET request to see what information is there in the File ID where we want to update something.

1. To make a GET request, drag-and-drop the GET *API Client* object onto the Dataflow.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/sLhox1QINGRQclTlkvx0/26-Patch-1692940847746.PNG)

2. Pass userID ‘1pGLAWbY7zu1nYFjMFB5GmTjVK2kXGHP1’ to the *id* under the *Parameters* node in the *API* *Client* object using the *Variable* transformation object.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/iwSE9ciLtylCxZdScwpq/27-UserID.PNG)

3. Right-click the *API Client* object’s header and select *Preview Output*.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/nJPdgiisFv7gCjerUSPZ/28-Preview-Output.PNG)

Here is what the output looks like:

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/n77KkKMvBlCnr0WCjCru/29-Output.PNG)

4. Drag-and-drop the *Update a file’s metadata* *API Client* object to use the PATCH method.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/ZcM6HN9H6yaaM6bUf0F6/30-Update.PNG)

5. Pass fileId’ 1pGLAWbY7zu1nYFjMFB5GmTjVK2kXGHP1’, and *name*, “Astera”, using a *Variables* resource object.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/2xP9PwWT0eVpJxc623O1/31-FIle-ID.PNG)

6. Right-click on the object’s header, and select *Preview Output*.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/mQYaLz8JaeNga4NqCVse/32-Preview.PNG)

You can see that the *HTTPStatusCode* is 200, which means that the API has successfully carried out the PATCH request. Let’s verify it by making a GET request for the same *fileId* which we altered.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/cwlZqt6Jwab2sVGuRMqs/33-Get.PNG)

7. Right-click the *APIClient* object’s header and select *Preview Output*.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/JPiS8snp1RDYIfNQn2Jv/34-Verify.PNG)

As you can see, the request has been successfully carried out and the *email* address has been updated.

This concludes our discussion on the HTTP method operations in Astera.
