GENDER API JAVA

Installier zuerst unsere Library mit Composer:

Link zur Client-Dokumentation auf Github:

https://github.com/markus-perl/gender-api-client

Installier zuerst unsere Library mit npm:

Link zur Client-Dokumentation auf Github:

https://github.com/markus-perl/gender-api-client-npm

Installier zuerst unsere Library mit npm:

Link zur Client-Dokumentation auf Github:

https://github.com/markus-perl/gender-api-client-npm

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import com.google.gson.Gson;
import com.google.gson.JsonObject;

public class Main {

  public static void main(String[] args) {

  try {

    String myKey = "insert your server key here";
    URL url = new URL("https://gender-api.com/get?key=" + myKey + "&name=markus");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();

    if (conn.getResponseCode() != 200) {
      throw new RuntimeException("Error: " + conn.getResponseCode());
    }

    InputStreamReader input = new InputStreamReader(conn.getInputStream());
    BufferedReader reader = new BufferedReader(input);

    Gson gson = new Gson();
    JsonObject json = gson.fromJson(reader, JsonObject.class);
    String gender = json.get("gender").getAsString();
    System.out.println("Gender: " + gender); // Gender: male
    conn.disconnect();

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

Beispielprojekte hier herunterladen:

Dokumentation:

https://github.com/microknights/Gender-API
Chat