HTTP verbs are the request methods we use along with the endpoints to access a particular api route.
Requisitions
One of the ways to make requests is to create PressListener for Button, in the example below I will demonstrate how to get the response of the request in a variable and display in a Label
PressListener
//String uri = Requisition URL//HttpMethod httpMethod = HTTP VerbsPressListenergetPressListener(finalString url,String httpType) {return (e) -> {//msg variable will be responsible for storing the request responseString msg ="";try {HttpStream.Options options =new HttpStream.Options();options.httpType= httpType;HttpStream httpStream =newHttpStream(new URI(url), options);ByteArrayStream bas =newByteArrayStream(4096);bas.readFully(httpStream,10,2048);String data =newString(bas.getBuffer(),0,bas.available());Response<ResponseData> response =newResponse<>();response.responseCode=httpStream.responseCode;if (httpStream.responseCode==200){response.data= (JSONFactory.parse(data,ResponseData.class));//Accessing the answer and picking up the information. msg +="Url: "+response.data.getUrl() +"\n"; msg +="Origin: "+response.data.getOrigin(); } } catch (IOException e1) { msg ="erro"; } catch (InstantiationException ex) {ex.printStackTrace(); } catch (InvocationTargetException ex) {ex.printStackTrace(); } catch (NoSuchMethodException ex) {ex.printStackTrace(); } catch (IllegalAccessException ex) {ex.printStackTrace(); }lblResult.setText(msg);lblResult.setRect(KEEP, KEEP, PREFERRED, PREFERRED); }; }publicstaticclassResponse<T> {publicT data;publicint responseCode; }
Creating the packet to receive the response in order to handle the data obtained from the request