-3

I'm new to rest api.

I need to make an api that takes a string as parameter and then return boolean.

Now my question is how to i pass that string to my api, and then get the string inside my api?

Nicklas
  • 39
  • 1
  • 4

1 Answers1

1

Here's one example that takes a string in parameter and has a default value if the query parameter is not provided:

@Path("business/department/")
public interface DepartmentService {

    @GET
    @Path("/cs/availability/chat")
    @Produces(MediaType.APPLICATION_JSON)
    boolean getCustomerServiceAvailability(@QueryParam("type") @DefaultValue("chat") String type);
}

and the implementation class can be anything that implements your interface. In this example, it's a stateless EJB

@Stateless
public class DepartmentServiceImpl implements DepartmentService {

@Context
private HttpServletRequest request;

private static final Logger LOGGER = Logger.getLogger(DepartmentServiceImpl.class.getName());


@Override
public boolean getCustomerServiceAvailability(String scheduleType) {

    RequestInfo reqInfo = new RequestInfo(request, this.getClass(), "getCustomerServiceAvailability");
    boolean available;
    try {
        available = CallBusinessService(scheduleType);
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, e.getLocalizedMessage());
        throw new ServiceException();
    } finally {
        reqInfo.logExecutionTime();
    }
}
}
Pat B
  • 1,915
  • 23
  • 40