Sending Requests
SuperTokensHttpURLConnection.newRequest
function: API Reference
The URL url = new URL("https://api.example.com/api/getUerInfo");
HttpURLConnection connection;
try {
connection = SuperTokensHttpURLConnection.newRequest(url, new SuperTokensHttpURLConnection.PreConnectCallback() {
@Override
public void doAction(HttpURLConnection con) throws IOException {
con.setRequestMethod("POST");
// set some custom headers..
}
});
if ( connection.getResponseCode() == 200 ) {
// handle response..
}
} catch (IOException e) {
// Something went wrong making the API call
} finally {
connection.disconnect();
}
val url = new URL("https://api.example.com/api/getUerInfo");
val connection;
try {
connection = SuperTokensHttpURLConnection.newRequest(url, SuperTokensHttpURLConnection.PreConnectCallback {
it.setRequestMethod("POST");
})
if ( connection.responseCode == 200 ) {
// handle response..
}
} catch (IOException e) {
// Something went wrong making the API call
} finally {
connection.disconnect();
}
- If the status code of the returned
connection
object is session expired, then you should ask the user to login again. - The callback may be called multiple times if the access token has expired.