cancel
Showing results for 
Search instead for 
Did you mean: 

How to do the designing of an array in rest api

import java.lang.reflect.Array;

import java.util.Arrays;

 

import javax.ws.rs.GET;

import javax.ws.rs.Path;

import javax.ws.rs.PathParam;

import javax.ws.rs.Produces;

import javax.ws.rs.core.MediaType;

 

import netscape.javascript.JSObject;

 

u/Path("PerfectNumber/{a},{b}")

u/Produces(MediaType.TEXT_PLAIN)

public class PerfectNo {

 

u/GET
public static int[] isPerfectNumber(@PathParam("a") int starting_number, u/PathParam("b") int ending_number)

{

int array\[\] = null;

int sum = 0;
int i;

for ( i=starting\_number; i<=ending\_number; i++)
{

for (int j=1 ; j<=i-1;j++)

{

if (i % j==0)

{

sum=sum+j;

}

}

if (sum==i)

{

array[array.length]=sum;

}

}

return array;

}

}

1 REPLY 1

Hi

REST does not require you use any methods beyond GET or POST, where the latter is used to invoke unsafe side-effects. REST simply requires HATEOAS, so all "resources" are discoverable by following links, and it requires that all requests consist either of some combination of raw data and "resources". "Resources" have specific properties defined by REST, ie. lifetime, designation by URL, etc. That's it, that's REST.

All this pervasive nonsense about human-readable URLs and requiring the use of specific HTTP verbs has nothing to do with REST. In fact, making them human-readable so people can link to URLs deep within an application is actually contrary to good REST design; HATEOAS means you should have a public entry point/URL, and navigate where you want to go because a URL can change at any time, ie. if a URL stops working, go back to the beginning and try to discover it again.

HTTP and REST shagle reduce to an object calculus, where GET is "inspect/navigate to object X", and POST is "invoke operation M on object X". HATEOAS is then simply the constraint that given object X, you can only navigate to any of X's members; POST is then used to modify server-side objects via method omegle invocations, where each method invocation can only be invoked with parameters that are data or other objects references (where "object reference" is a "resource" in REST terminology that has specific properties).