# HTTP Requests with Java

## GET Request

**Test Get all Users**

```java
@Test
public void testGetAllUsers(){
  
  given()
    .when()
      .get("/users")  
    .then()      
      .statusCode(200)
}
```

## POST Request

**Test Create User**

```java
@Test
public void testCreateUser(){
  
  User user = new User("John", "Doe", 30);
  
  given()
    .body(user)
   .when()     
     .post("/users")
   .then()
     .statusCode(201)
}
```

## PUT Request

**Test Update User**

```java
@Test
public void testUpdateUser(){
  
  User updatedUser = new User("John", "Smith", 31);
  
  given()
    .pathParam("id", 1)
    .body(updatedUser)
   .when()     
     .put("/users/{id}") 
   .then()
     .statusCode(200)  
}
```

## PATCH Request

**Test Update User Name**

```java
@Test        
public void testUpdateUserName(){

  given()
    .pathParam("id", 1)
    .body("John Doe")  
  .when()        
    .patch("/users/{id}/name")
  .then()
    .statusCode(200)         
}
```

## DELETE Request

**Test Delete User**

```java
@Test
public void testDeleteUser(){

  given() 
    .pathParam("id", 1)   
  .when()      
    .delete("/users/{id}")
  .then()
    .statusCode(200)
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://qatesting.gitbook.io/qa/api-testing/api-tools/postman/http-requests-with-java.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
