@Consumes: type of data the method can take as input. The data will automatically be deserialized into a method input parameter. For example, you can pass a wine object to the addWined() method either as JSON or XML. The JSON or XML representation of a new wine is automatically deserialized into the Wine object passed as an argument to the method.

@Produces: One or more response content type(s) the method can generate. The method’s return value will be automatically serialized using the content type requested by the client. If the client didn’t request a specific content type, the first content type listed in the @Produces annotation will be used. For example, if you access http://coenraets.org/rest/wines, you get a list of wines represented as JSON because it is the first content type listed in the @Produces annotation of the findAll() method.

Here is the jQuery code involved in calling the services:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

functionfindAll() {

$.ajax({

type: 'GET',

url: rootURL,

dataType: "json", // data type of response

success: renderList

});

}

functionfindByName(searchKey) {

$.ajax({

type: 'GET',

url: rootURL + '/search/'+ searchKey,

dataType: "json",

success: renderList

});

}

functionfindById(id) {

$.ajax({

type: 'GET',

url: rootURL + '/'+ id,

dataType: "json",

success: function(data){

$('#btnDelete').show();

renderDetails(data);

}

});

}

functionaddWine() {

console.log('addWine');

$.ajax({

type: 'POST',

contentType: 'application/json',

url: rootURL,

dataType: "json",

data: formToJSON(),

success: function(data, textStatus, jqXHR){

alert('Wine created successfully');

$('#btnDelete').show();

$('#wineId').val(data.id);

},

error: function(jqXHR, textStatus, errorThrown){

alert('addWine error: '+ textStatus);

}

});

}

functionupdateWine() {

$.ajax({

type: 'PUT',

contentType: 'application/json',

url: rootURL + '/'+ $('#wineId').val(),

dataType: "json",

data: formToJSON(),

success: function(data, textStatus, jqXHR){

alert('Wine updated successfully');

},

error: function(jqXHR, textStatus, errorThrown){

alert('updateWine error: '+ textStatus);

}

});

}

functiondeleteWine() {

console.log('deleteWine');

$.ajax({

type: 'DELETE',

url: rootURL + '/'+ $('#wineId').val(),

success: function(data, textStatus, jqXHR){

alert('Wine deleted successfully');

},

error: function(jqXHR, textStatus, errorThrown){

alert('deleteWine error');

}

});

}

// Helper function to serialize all the form fields into a JSON string