Skip to content

Commit b3c4e83

Browse files
authored
Update README.md
1 parent 81aaef2 commit b3c4e83

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

README.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,135 @@
11
# APIService_XML_JSON_JAVA_Servlet
22
Implementation of an API Service to query on user data which is stored in xml file and mapped to the APIServlet GET method and returning a JSON Array
3+
4+
## API
5+
6+
**Application Programming Interface** or API is a software intermediary that allows two applications to 'talk' to each other.
7+
When you use an application on your mobile phone, this is what happens:
8+
- The application connects to the Internet and sends data to a server.
9+
- The server then retrieves that data, interprets it, and performs the necessary actions and sends it back to your phone.
10+
- The application then interprets that data and presents the information that you wanted in a readable format.
11+
All this is done through an API.
12+
13+
## Task details
14+
15+
Your task is to implement an API service to query on user data which is stored in **_com.he.api.data.xml_** in the following format.
16+
17+
```
18+
<dataset id_auto_increment="3"›
19+
<user id="1" firstName="John" lastName="Dawson"/>
20+
<user id="2" firstName="John" lastName="Doe"/>
21+
</dataset>
22+
```
23+
- ``` <dataset> ``` tag is the root element in the XML document. It has a single attribute **_id_auto_increment_**. The value of Its ID increases as follows: value of the user's ID that was added last + 1
24+
- ``` <user /> ``` tag represents a user record in the dataset. It has following attributes:
25+
26+
- id: Primary key of the user data. It is an integer value.
27+
- firstName: First name of the user. It is a string value that contains only lowercase and uppercase letters of the English alphabet.
28+
- IastName: Last name of the user. It is a string value that contains only lowercase and uppercase letters of the English alphabet.
29+
30+
The call to server would be made by
31+
```scheme://domain:port/API?action=#&id=#&firstName=#&lastName=#```, where 'string' after '?' denotes the query string.
32+
33+
You have to implement an API service that is mapped to the **_APIServlet_** (com.he.api.APIServlet.java) **_GET Method_** (at URL scheme://domain:port/API).
34+
The query string (read more about query strings here) may have following parameters:
35+
36+
- action: Defines what operations need to be performed
37+
- id
38+
- firstName
39+
- IastName
40+
41+
## Types of queries
42+
43+
The queries can be of the following types:
44+
- **action=searchByld&id=#**: Search by id in the dataset in the data.xml file. Return a JSON array that contains the selected user as a response.
45+
46+
Example URL:
47+
```scheme://domain:port/API?action=searchById&id=1```
48+
49+
Response:
50+
```
51+
[{
52+
"id": 1,
53+
"firstName": "John",
54+
"lastName": "Dawson"
55+
}l
56+
```
57+
- **action=searchByFirstName&firstName=#**: Search by firstName in the dataset in the data.xml file. Return a JSON array that contains the selected user(s) as a response.
58+
59+
Example URL:
60+
```scheme://domain:port/API?action=searchByFirstName&firstName=John ```
61+
62+
Response:
63+
```
64+
[{
65+
"id": 1,
66+
"firstName": "John",
67+
"lastName": "Dawson"
68+
}, {
69+
"id": 2,
70+
"firstName": "John",
71+
"lastName": "Doe"
72+
}]
73+
```
74+
- **action=searchByFirstName&IastName=#**: Search by lastName in the dataset in data.xml. Return a JSON array that contains the selected user(s) as a response.
75+
76+
Example URL:
77+
```scheme://domain:port/API?action=searchByLastName&lastName=Doe ```
78+
79+
Response:
80+
```
81+
[{
82+
"id": 2,
83+
"firstName": "John",
84+
"lastName": "Doe"
85+
}]
86+
```
87+
- **action=searchByldRange&low=#&high=#**: Search by id in the dataset in the data.xml file. Return a JSON array that contains the selected user(s) whose id is in the range [low,high] as a response.
88+
89+
Example URL:
90+
```scheme://domain:port/API?action=searchByIdRange&low=1&high=2 ```
91+
92+
Response:
93+
```
94+
[{
95+
"id": 1,
96+
"firstName": "John",
97+
"lastName": "Dawson"
98+
}, {
99+
"id": 2,
100+
"firstName": "John",
101+
"lastName": "Doe"
102+
}]
103+
```
104+
- **action=updateUser&id=#&firstName=#&lastName=#**: Update the user in the data.xml file, which is given by id, and set the firstName and IastName to given values. If firstName or IastName parameter are not present then it's value is left unchanged. It may be possible that only firstName is present and lastName is null, then only firstName has to be updated.
105+
106+
Example URL:
107+
```scheme://domain:port/API?action=updateUser&id=1&firstName=James&lastName=Jackson ```
108+
109+
```
110+
<dataset id auto increment="3">
111+
<user id="1" firstName="James" lastName="Jackson"/>
112+
<user id="2" firstName="John" lastName="Doe"/>
113+
</dataset>
114+
```
115+
116+
- **action=insertUser&firstName=#&IastName=#**: Insert a user record in the data.xml file by using the following parameters:
117+
- firstName
118+
- IastName
119+
120+
The ID of the user is given by the id_auto_increment parameter of the root dataset tag. After the value is inserted, the id_auto_increment parameter is incremented by 1.
121+
122+
Example URL:
123+
```scheme://domain:port/API?action=insertUser&firstName=James&lastName=Jackson ```
124+
125+
```
126+
<dataset id auto increment="4">
127+
<user id="1" firstName="John" lastName="Dawson"/>
128+
<user id="2" firstName="John" lastName="Doe"/>
129+
<user id="3" firstName="James" lastName="Jackson"/>
130+
</dataset>
131+
```
132+
133+
## Testing
134+
Test your API implementation by comparing the mapping of your JSON array and XML DOM.
135+

0 commit comments

Comments
 (0)