Skip to content

Commit b0d0623

Browse files
committed
final commit
1 parent 974237f commit b0d0623

File tree

11 files changed

+41
-18
lines changed

11 files changed

+41
-18
lines changed

img.png

70.4 KB
Loading

img_1.png

70.4 KB
Loading

img_2.png

51.7 KB
Loading

img_3.png

52.5 KB
Loading

img_4.png

62.7 KB
Loading

img_5.png

54.3 KB
Loading

img_6.png

53.3 KB
Loading

img_7.png

44.8 KB
Loading

readme.md

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,43 @@ This is a Java application that provides a REST API with endpoints for searching
55

66
Project developed as part of an assignment by Kaiburr.
77

8-
### Table of contents
8+
## Table of contents
99
- Usage
1010
- Endpoints
1111
- Examples
1212

13-
### Usage
14-
1. Download "server.jar" file into your local repository and cd into it
15-
2. Make sure you have jdk 19 and mongodb 6 installed on your machine
16-
3. start mongodb on your linux machine
17-
4. run server.jar file
18-
19-
### Endpoints
20-
21-
22-
### Examples
23-
13+
## Installation
14+
1. Download **server.jar** file into your local repository and cd into it
15+
2. Make sure you have jdk 19 and mongodb 6 installed on your machine
16+
3. start mongodb on your machine. On linux that would be using:
17+
> sudo sytemctl start mongod
18+
4. run **server.jar** file
19+
20+
## Usage
21+
Use **postman** to get, post and delete
22+
23+
## Endpoints
24+
- GET **'/'** - returns all server objects as json
25+
- GET **'/{id}'** - returns the server object that matches that id else returns a 404
26+
- GET **'/name/{name}'** - returns all server objects with names that contain the {name} string, else returns a 404
27+
- PUT **'/'** - takes in a JSON encoded message body and stores it in a mongodb server
28+
- DELETE **'/{id}'** - deletes the serves that the has {id} as its id
29+
30+
## Examples
31+
Examples of the API using **Postman**
32+
- GET **'/'** :
33+
![img_1.png](img_1.png)
34+
- GET **'/{id}'** :
35+
- when id is found:
36+
![img_2.png](img_2.png)
37+
- when id is not found:
38+
![img_3.png](img_3.png)
39+
- GET **'/name/{name}'** :
40+
- when name is found:
41+
![img_4.png](img_4.png)
42+
- when name is not found:
43+
![img_5.png](img_5.png)
44+
- PUT **'/'**:
45+
![img_6.png](img_6.png)
46+
- DELETE **'/{id}'**:
47+
![img_7.png](img_7.png)

server.jar

23.5 MB
Binary file not shown.

src/main/java/com/example/server/controller/ServerController.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.springframework.http.HttpStatus;
77
import org.springframework.http.ResponseEntity;
88
import org.springframework.web.bind.annotation.*;
9-
import org.springframework.web.client.ResourceAccessException;
109

1110
import java.util.ArrayList;
1211
import java.util.List;
@@ -53,14 +52,14 @@ public List<Server> returnByName(@PathVariable String name){
5352
}
5453
return s;
5554
}
56-
57-
// takes in server objects as JSON
58-
@PostMapping
59-
public ResponseEntity<?> saveByJSON(@RequestBody Server server){
55+
56+
// takes in server objects through a JSON encoded message body
57+
@PutMapping
58+
public ResponseEntity<?> saveByJSON(@RequestBody Server server) {
6059
repository.save(server);
6160
return new ResponseEntity<>("Server Added Successfully", HttpStatus.OK);
6261
}
63-
62+
6463
// deletes server based on ID given
6564
@DeleteMapping("{id}")
6665
public ResponseEntity<?> deleteById(@PathVariable String id){

0 commit comments

Comments
 (0)