> For the complete documentation index, see [llms.txt](https://walkinthepark.gitbook.io/microservice-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://walkinthepark.gitbook.io/microservice-api/reference/intro-making-requests/make-request-spigot.md).

# Make request: Spigot

## Example for making your first request

In this class, I will walk you through the process of utilizing **all four HTTP methods**. If you\
have prior experience with microservices or basic HTTP requests, the concepts should be straightforward to understand.

{% tabs %}
{% tab title="Make a request (Response)" %}
These methods direct requests to specific endpoints. The final step is to implement\
the logic for these methods within your microservice application.

{% code title="PlayerRepository.java" %}

```java
import micro.api.service.*;
import micro.api.payload.*;

public class PlayerRepository extends ServiceEndpoint {
   /**
    * This points to `http://localhost:5000/api/player`
    */
    public PlayerRepository(ServiceHost host) {
       super("/player", host);
    }

    /**
     * Example of GET request, get player's data.
     * @return a new PlayerClient object.
     */
    public PlayerClient loadPlayer(UUID uuid) {
        Query query = new Query();
        query.add("uuid", uuid.toString());

        return super.get("/load", PlayerClient.class, query);
    }
    
    /**
     * Example of POST request, add a new friend.
     * @return The updated PlayerClient object.
     */
    public PlayerClient addFriend(UUID uuid, UUID target) {
        Body body = new Body();
        body.add("uuid", uuid.toString());
        body.add("target", target.toString());

        return super.post("/friend_add", PlayerClient.class, body);
    }
    
    /**
     * Example of PUT request, update player's coins.
     * @return The updated PlayerClient object.
     */
    public PlayerClient updateCoins(UUID uuid, int amount) {
        Body body = new Body();
        body.add("uuid", uuid.toString());
        body.add("coins", amount);

        return super.put("/coin_update", PlayerClient.class, body);
    }
    
    /**
     * Example of DELETE request, delete player data.
     * @return The deleted PlayerClient object.
     */
    public PlayerClient deletePlayer(UUID uuid) {
        Query query = new Query();
        query.add("uuid", uuid.toString());
        
        return super.delete("/delete", PlayerClient.class, query);
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="Make a request (No response)" %}
{% hint style="info" %}
**Information**

As you can tell in this class, there's **no** GET request example, because a GET request always returns a value or content of some sort, hence why it's called GET.&#x20;
{% endhint %}

This is the same class as the previous example, only this time we don't serialize the response into an object, we simply ask for the status code.

```java
import micro.api.service.*;
import micro.api.payload.*;

public class PlayerRepository extends ServiceEndpoint {
   /**
    * This points to `http://localhost:5000/api/player`
    */
    public PlayerRepository(ServiceHost host) {
       super("/player", host);
    }

    /**
     * Example of POST request, add a new friend.
     * @return A status code object of the request.
     */
    public ServiceResponse addFriend(UUID uuid, UUID target) {
        Body body = new Body();
        body.add("uuid", uuid.toString());
        body.add("target", target.toString());

        return super.post("/friend_add", body);
    }
    
    /**
     * Example of PUT request, update player's coins.
     * @return A status code object of the request.
     */
    public ServiceResponse updateCoins(UUID uuid, int amount) {
        Body body = new Body();
        body.add("uuid", uuid.toString());
        body.add("coins", amount);

        return super.put("/coin_update", body);
    }
    
    /**
     * Example of DELETE request, delete player data.
     * @return A status code object of the request.
     */
    public ServiceResponse deletePlayer(UUID uuid) {
        Query query = new Query();
        query.add("uuid", uuid.toString());
        
        return super.delete("/delete", query);
    }
}
```

\
As you can see in this example, instead of returning a serialized object, it returns an object with a status code of the request. The *ServiceResponse* is actually an enumerator which holds the most common status codes of a request;

```java
/**
 * Most common status codes in a microservice.
 */
public enum ServiceResponse {
    OK(200),
    Created(201),
    Accepted(202),
    NoContent(204),
    BadRequest(400),
    Unauthorized(401),
    Forbidden(403),
    NotFound(404),
    NotAllowed(405),
    Conflict(409),
    InternalServerError(500),
    NotImplemented(501),
    ServiceUnavailable(503),
    Unknown(-1);

    private final int code;

    ServiceResponse(int code) {
        this.code = code;
    }

    public int getStatusCode() {
        return code;
    }
}
```

{% endtab %}

{% tab title="PlayerClient.java" %}

<pre class="language-java" data-title="PlayerClient.java"><code class="lang-java">public class PlayerClient {
   /**
    * These fields will get initialized when
    * loading the player from the service.
    */
   private String uuid;
   private int level;
   private <a data-footnote-ref href="#user-content-fn-1">Rank</a> rank;
   private int coins;
   private List&#x3C;String> friends;

   public UUID getUUID() { 
      return UUID.fromString(uuid); 
   }

   public int getLevel() {
       return level;
   }

   public <a data-footnote-ref href="#user-content-fn-1">Rank</a> getRank() {
      return rank;
   }

   public int getCoins() {
      return coins;
   }
   
   public List&#x3C;String> getFriends() {
       return friends;
   }
}
</code></pre>

{% endtab %}
{% endtabs %}

[^1]: ```java
    public enum Rank {
        PLAYER,
        HELPER,
        MODERATOR,
        ADMIN,
        OWNER,
    }
    ```
