# 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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FvcVFaer7a5GQJ2XLx069%2F11-Limit-Three.PNG?alt=media\&token=52c69b5b-df09-42b9-936a-55ad2dffca14)

{% 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/astera-data-stack-v10/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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FmGEEdL0Xg51xkyNx4IRq%2F02-Endpoint.PNG?alt=media\&token=9009511e-83fa-4d6a-abf7-2070abf368f3)

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/astera-data-stack-v10/dataflows/transformations/constant-value-transformation) object.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2F32UkcuPW00GqCSSX53Ax%2F03-GET.PNG?alt=media\&token=094e2ce0-8c79-46d0-806a-b97c7a07a848)

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FqZ24RQbOr4wu1MidhMF8%2F03-Prop.png?alt=media\&token=87c1d7e0-0954-4d67-8f42-f575aea43f7e)

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FnzUXqn9etzq9ssKDHwyX%2F04-Connection.PNG?alt=media\&token=a1d61201-ac2a-484d-87d6-61ce66d6750a)

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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FizFCNcBJwguEuQaXH66k%2F06-Parameter.PNG?alt=media\&token=d3472f65-0d53-4da9-81fd-1a3c335b3b52)

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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FGupxc37XARTO0HwG9KMA%2F07-Output-Layout.PNG?alt=media\&token=9670873c-d9d5-47a0-999f-0833c6eb02b6)

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

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FEqshWKh1tuAFtU9bSILe%2F08-Pagination.PNG?alt=media\&token=0d2a0e1d-c304-4443-9d2d-c9ae327c2e92)

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FeNY8NKNWcAjTCYxpr3EY%2F09-Preview.PNG?alt=media\&token=874295f2-1a63-4180-ae61-a174a4dbdb28)

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2Fpbt1QvAVjHDd7B2ykKIL%2F10-Data.PNG?alt=media\&token=9ec6828a-8202-4bca-8579-7efb0f7e117c)

### 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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2F9E7WNE1EWvXBvfyF6Ksk%2F11-Client.PNG?alt=media\&token=45c227f2-cb58-4dd5-9bc2-e7185e3b1e7f)

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2F4iTVw1hSC7HeHrwNWlgl%2F12-Post.PNG?alt=media\&token=4f2b890c-2d3f-4e5c-b10d-8e4b2a3be211)

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FE0Kju48nfb91pKAEGERD%2F13-Preview.PNG?alt=media\&token=a291b28c-ceab-48f0-9f2a-4a0725e47efc)

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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FdEPxmjWZLyOShCcdSCMI%2F14-Flow.PNG?alt=media\&token=e44c1b52-888d-4d29-ab87-3a74aa1d668f)

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FeDTMVVXc22wxHVZ3jSmd%2F15-Preview-Final.PNG?alt=media\&token=b2c1eb97-9d03-44d0-b819-4cc815babc2e)

### 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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FVAWo3ozvkBJ5Ri9ThJi6%2F16-Petstore.PNG?alt=media\&token=13ccfe00-e398-402d-b997-f687d88a1b2b)

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2Fa9WL5HmnnxPjXBEVe5Ce%2F17-PetID.PNG?alt=media\&token=d46acd83-6f95-4f20-9af3-e75f358b55b4)

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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FsjWCCDbFKr0DUXysmhAG%2F18-Delete.PNG?alt=media\&token=274619f6-0920-4996-9c45-007c3fc35884)

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2Fjq5Oe3eE3laLoIaF6L7m%2F19-01-Verify.PNG?alt=media\&token=64e35086-89be-4fd6-8a25-a5f119f9c316)

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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2F2GXZCMDKHVegn2tuNqD6%2F19-Deleted-Success.PNG?alt=media\&token=3c30a20f-d3e1-446c-a2f0-ad106e8f88c4)

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2Fqu9vuWl3iQiC2FLqCe4G%2F20-Verify.PNG?alt=media\&token=be2750bf-fbe3-4e16-a60c-37436872a6b1)

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FAVDsk9f9qqjCxdelFs1B%2F25-DELETE-Preview-GET.PNG?alt=media\&token=644136ea-e56b-4194-8528-7afc21cad7f8)

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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FPiYiMth1r1qTJ93wokfN%2F22-Get.PNG?alt=media\&token=53561689-72fa-4d58-a9d4-4f0eb8cc4309)

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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FMkhPHX4MzAUxBWXRj6x7%2F23-File.PNG?alt=media\&token=fa8c8887-a5bf-414d-9fe4-b2129e14c683)

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FnyXoriMjJiaYGS89YS4l%2F24-Preview.PNG?alt=media\&token=c54f240f-1cac-40dd-b88c-930d4f479124)

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FWeGlgqAWNXWFQufTTPf4%2F25-Retrieved.PNG?alt=media\&token=98ae3b3e-6f0a-4ca4-9b7a-583019aecd30)

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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2F4oxu5ib7oxlfGgz0nuKD%2F35-Put-Patch.PNG?alt=media\&token=043a5996-40b1-4e52-b774-e56bc243cc24)

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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FJqqAZlQq5msbP8JpJkjR%2F36-Output-ID.PNG?alt=media\&token=475c45d1-e6b2-482a-afa6-3af89c10ec0f)

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

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FZ3qzZbITjBRbarvdoNUj%2F38-Updated.PNG?alt=media\&token=8b205738-9361-427b-bcb3-96d5800862c0)

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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FDZ35H1JfcIzs7XqWIiqh%2F39-GET-Verify.PNG?alt=media\&token=259a41ac-26a9-41e8-80b4-e9313bedbb43)

### 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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2F8KBJZ4xYeglTrKogoY3P%2F26-Patch-1692940847746.PNG?alt=media\&token=3514e84a-040c-4f13-8c8e-60d7500889f0)

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FC22DrdGsYwvCLW8IUq0W%2F27-UserID.PNG?alt=media\&token=3589a41e-a5e9-4761-beea-6b0ba8ba97a5)

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2F9VWLpKOangtG9fHmrmzg%2F28-Preview-Output.PNG?alt=media\&token=3a91f704-b284-4e18-ad7f-96904665cc58)

Here is what the output looks like:

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FMacevrkTztCMTOveP0DG%2F29-Output.PNG?alt=media\&token=2b4947f0-242e-43dd-9bd9-d020debb7d39)

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FacKg14tg8XAHTYFq3lqE%2F30-Update.PNG?alt=media\&token=9e9d6ec8-f3fe-4274-9c55-33992d947adc)

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2F3lXzNofG8zwisC92WMB2%2F31-FIle-ID.PNG?alt=media\&token=1f9512a2-6280-4c83-9ef6-c9d1a8ece114)

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2F2a4VKvgo50TlUketehE7%2F32-Preview.PNG?alt=media\&token=a7769785-3280-451e-8a65-c1da07af4fc6)

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://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FVRIDPCJrNavMX9PRym9c%2F33-Get.PNG?alt=media\&token=b639fb03-c6a7-404c-a2d6-bd010bbf377f)

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

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2Fa4GWrEqSfQRL8hHMXntt%2F34-Verify.PNG?alt=media\&token=c54e40c9-a348-4a3a-a401-1231feb924ca)

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.
