Still super new to REST, but close to finishing my first program.
I am attempting to create a CSV with the value of the POST URL Parameter being passed into it each time I POST.
Is there a way of setting my variable to be equal to my POST URL Parameter?
Code below (value is temporarily set to 10 while I figure this out):
@Path("/values")
public class values {
int totalSum = 0;
List<String> list = new ArrayList<String>();
@GET
@Produces(MediaType.TEXT_PLAIN)
public int getSum() throws IOException {
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
List<String[]> read = reader.readAll();
return sum.sum(read, totalSum);
}
@POST
public String addValue() throws IOException {
int value = 10;
String valueString = Integer.toString(value);
CSVWriter writer = new CSVWriter(new FileWriter("yourfile.csv", true), ',');
String[] entries = valueString.split(",");
writer.writeNext(entries);
writer.close();
return "ok";
}
@DELETE
@Produces(MediaType.TEXT_PLAIN)
public String deleteList() throws IOException {
FileWriter fw = new FileWriter("yourfile.csv", false);
PrintWriter pw = new PrintWriter(fw, false);
pw.flush();
pw.close();
fw.close();
return "ok";
}
}