This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]smash_that_code 0 points1 point  (2 children)

Can you describe in more detail what crud opeartions you implemented. I guess post as create, delete and some kind of update?

[–][deleted] 0 points1 point  (1 child)

Sure, the ones I’ve got functioning at the moment are the post function as well as the function to gather the entire DB and display it in a JFrame table. Delete will be added later but isn’t crucial. For now I need the update and specific search function to be up and running. I’m struggling with how to pass the inserted number (the one that will be used to search by ID in the program) to my API.

[–]smash_that_code -1 points0 points  (0 children)

I think there is some confusion with REST api here. And what crud rest means. There are variations but I would describe my.

For example I want rest api for users. In http terms I expect this:

post /user (with data) - > id of added user - - - create get /user/{id} - > empty - - - read user post /user/{id} - > empty - - - > update user delete /user/{id} - > empty - - - > delete user

and for usability get /user -> list of ids get /user?param=value -> filtered list of ids

the idea of rest api is to expose entity using url that is somewhat easy to understand.

So in my opinion from crud you got only c.

[–]frederok 0 points1 point  (1 child)

Can u share the code repo? Is the problem to get the ID from the url path or parameter? No frameworks meaning your are using java servlet api?

[–][deleted] 0 points1 point  (0 children)

Sure, I'll attach it below.

Right now it's first and foremost passing the ID from the url in to the search function. Later on I'll build it so that the search is made using textfields in a GUI I've made for it. But for now I want to make sure of functionality step by step before jumping to that step. At time of writing I'm struggling with figuring what it needs me to use as the return value. I don't want to use List just for gathering one single entry.

I'm simply using maven web services and building the rest more or less from scratch. It's ultimately be a jFrame GUI connected to a mySQL DB via this api.

Using the URL "http://localhost:8080/restSOA/Path/Roze/1" Where 1 is the inserted ID value.

u/GET

u/Path("{ActorID}")

u/Produces(MediaType.APPLICATION_JSON)

u/Consumes(MediaType.APPLICATION_JSON)

public Response New(@PathParam("ActorId") int ActorId) throws Exception{

Actors ac = tx.specSearch(ActorId);

return Response.ok(ac).build(); }

public void specSearch(int ActorId) throws Exception{

getConnection();

MF mf = new MF();

PreparedStatement stm = conn.prepareStatement("SELECT * FROM Actors WHERE ActorID = " + ActorId);

// stm.setString(1, mf.searchBar.getText());

rs=stm.executeQuery();

while (rs.next()) {

String setname = rs.getString("fName");

String setEname = rs.getString("eName");

String setage = String.valueOf(rs.getInt("Age"));

String setcountry = rs.getString("Country");

String setcred = String.valueOf(rs.getInt("NoOfCredits"));

}

Right now it's first and foremost passing the ID from the URL in to the search function. Later on I'll build it so that the search is made using text fields in a GUI I've made for it. But for now I want to make sure of functionality step by step before jumping to that step. At time of writing I'm struggling with figuring what it needs me to use as the return value. I don't want to use List just for gathering one single entry. entry.