Skip to content

Commit c8a3890

Browse files
Added Swagger UI and changed Mapping annotations for LessonAPI
1 parent d8da2cd commit c8a3890

30 files changed

+308
-207
lines changed

.factorypath

Lines changed: 69 additions & 54 deletions
Large diffs are not rendered by default.

CourseAPI-PROD.postman_collection.json

Lines changed: 85 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"variables": [],
33
"info": {
44
"name": "CourseAPI-PROD",
5-
"_postman_id": "24b0de1e-b4a7-acfb-0780-493752bb4f1e",
5+
"_postman_id": "4d73314a-8fa9-7970-764e-13b6885a2895",
66
"description": "https://github.com/SwarnadeepGhosh/Java-Backend/tree/master/CourseAPI-Spring-Starter",
77
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
88
},
@@ -14,18 +14,21 @@
1414
{
1515
"name": "GetAllCourse By Topic",
1616
"request": {
17-
"url": "http://courseapi-spring-boot.herokuapp.com/topics/java/courses",
17+
"url": "https://courseapi-spring-boot.herokuapp.com/topics/java/courses",
1818
"method": "GET",
1919
"header": [],
20-
"body": {},
20+
"body": {
21+
"mode": "raw",
22+
"raw": ""
23+
},
2124
"description": "We will get all courses associated with one topic."
2225
},
2326
"response": []
2427
},
2528
{
2629
"name": "Add a Course",
2730
"request": {
28-
"url": "http://courseapi-spring-boot.herokuapp.com/topics/java/courses",
31+
"url": "https://courseapi-spring-boot.herokuapp.com/topics/java/courses",
2932
"method": "POST",
3033
"header": [
3134
{
@@ -45,18 +48,21 @@
4548
{
4649
"name": "Get a Course for a Topic",
4750
"request": {
48-
"url": "http://courseapi-spring-boot.herokuapp.com/topics/java/courses/java-streams",
51+
"url": "https://courseapi-spring-boot.herokuapp.com/topics/java/courses/java-streams",
4952
"method": "GET",
5053
"header": [],
51-
"body": {},
54+
"body": {
55+
"mode": "raw",
56+
"raw": ""
57+
},
5258
"description": ""
5359
},
5460
"response": []
5561
},
5662
{
5763
"name": "Update (PUT) a Course",
5864
"request": {
59-
"url": "http://courseapi-spring-boot.herokuapp.com/topics/java/courses/java-streams",
65+
"url": "https://courseapi-spring-boot.herokuapp.com/topics/java/courses/java-streams",
6066
"method": "PUT",
6167
"header": [
6268
{
@@ -76,7 +82,7 @@
7682
{
7783
"name": "Delete a Course",
7884
"request": {
79-
"url": "http://courseapi-spring-boot.herokuapp.com/topics/java/courses/java-streams",
85+
"url": "https://courseapi-spring-boot.herokuapp.com/topics/java/courses/java-streams",
8086
"method": "DELETE",
8187
"header": [
8288
{
@@ -102,18 +108,21 @@
102108
{
103109
"name": "GetAllLessons By Course",
104110
"request": {
105-
"url": "http://courseapi-spring-boot.herokuapp.com/topics/java/courses/java-8/lessons",
111+
"url": "https://courseapi-spring-boot.herokuapp.com/topics/java/courses/java-8/lessons",
106112
"method": "GET",
107113
"header": [],
108-
"body": {},
114+
"body": {
115+
"mode": "raw",
116+
"raw": ""
117+
},
109118
"description": "We will get all courses associated with one topic."
110119
},
111120
"response": []
112121
},
113122
{
114123
"name": "Add a Lesson",
115124
"request": {
116-
"url": "http://courseapi-spring-boot.herokuapp.com/topics/java/courses/java-8/lessons",
125+
"url": "https://courseapi-spring-boot.herokuapp.com/topics/java/courses/java-8/lessons",
117126
"method": "POST",
118127
"header": [
119128
{
@@ -133,18 +142,21 @@
133142
{
134143
"name": "Get a Lesson for a Course",
135144
"request": {
136-
"url": "http://courseapi-spring-boot.herokuapp.com/topics/java/courses/java-8/lessons/java-lambda",
145+
"url": "https://courseapi-spring-boot.herokuapp.com/topics/java/courses/java-8/lessons/java-lambda",
137146
"method": "GET",
138147
"header": [],
139-
"body": {},
148+
"body": {
149+
"mode": "raw",
150+
"raw": ""
151+
},
140152
"description": ""
141153
},
142154
"response": []
143155
},
144156
{
145157
"name": "Update (PUT) a Lesson",
146158
"request": {
147-
"url": "http://courseapi-spring-boot.herokuapp.com/topics/java/courses/java-8/lessons/java-lambda",
159+
"url": "https://courseapi-spring-boot.herokuapp.com/topics/java/courses/java-8/lessons/java-lambda",
148160
"method": "PUT",
149161
"header": [
150162
{
@@ -164,7 +176,7 @@
164176
{
165177
"name": "Delete a Lesson",
166178
"request": {
167-
"url": "http://courseapi-spring-boot.herokuapp.com/topics/java/courses/java-8/lessons/java-collection",
179+
"url": "https://courseapi-spring-boot.herokuapp.com/topics/java/courses/java-8/lessons/java-collection",
168180
"method": "DELETE",
169181
"header": [
170182
{
@@ -190,29 +202,35 @@
190202
{
191203
"name": "List All Topics /topics",
192204
"request": {
193-
"url": "http://courseapi-spring-boot.herokuapp.com/topics",
205+
"url": "https://courseapi-spring-boot.herokuapp.com/topics",
194206
"method": "GET",
195207
"header": [],
196-
"body": {},
208+
"body": {
209+
"mode": "raw",
210+
"raw": ""
211+
},
197212
"description": "List all topics"
198213
},
199214
"response": []
200215
},
201216
{
202217
"name": "Get One Topic /topics/id",
203218
"request": {
204-
"url": "http://courseapi-spring-boot.herokuapp.com/topics/js",
219+
"url": "https://courseapi-spring-boot.herokuapp.com/topics/js",
205220
"method": "GET",
206221
"header": [],
207-
"body": {},
222+
"body": {
223+
"mode": "raw",
224+
"raw": ""
225+
},
208226
"description": "Get a specific topics"
209227
},
210228
"response": []
211229
},
212230
{
213231
"name": "POST (Add a topic) /topics",
214232
"request": {
215-
"url": "http://courseapi-spring-boot.herokuapp.com/topics",
233+
"url": "https://courseapi-spring-boot.herokuapp.com/topics",
216234
"method": "POST",
217235
"header": [
218236
{
@@ -232,7 +250,7 @@
232250
{
233251
"name": "PUT (Update) /topics/id",
234252
"request": {
235-
"url": "http://courseapi-spring-boot.herokuapp.com/topics/js",
253+
"url": "https://courseapi-spring-boot.herokuapp.com/topics/js",
236254
"method": "PUT",
237255
"header": [
238256
{
@@ -252,10 +270,13 @@
252270
{
253271
"name": "Delete a topic /topics/id",
254272
"request": {
255-
"url": "http://courseapi-spring-boot.herokuapp.com/topics/javaee",
273+
"url": "https://courseapi-spring-boot.herokuapp.com/topics/javaee",
256274
"method": "DELETE",
257275
"header": [],
258-
"body": {},
276+
"body": {
277+
"mode": "raw",
278+
"raw": ""
279+
},
259280
"description": "Deletes the specific topic"
260281
},
261282
"response": []
@@ -269,7 +290,7 @@
269290
{
270291
"name": "All links Actuator",
271292
"request": {
272-
"url": "http://courseapi-spring-boot.herokuapp.com/actuator",
293+
"url": "https://courseapi-spring-boot.herokuapp.com/actuator",
273294
"method": "GET",
274295
"header": [],
275296
"body": {},
@@ -280,7 +301,7 @@
280301
{
281302
"name": "Health",
282303
"request": {
283-
"url": "http://courseapi-spring-boot.herokuapp.com/actuator/health",
304+
"url": "https://courseapi-spring-boot.herokuapp.com/actuator/health",
284305
"method": "GET",
285306
"header": [],
286307
"body": {},
@@ -291,10 +312,47 @@
291312
{
292313
"name": "Beans Health",
293314
"request": {
294-
"url": "http://courseapi-spring-boot.herokuapp.com/beans",
315+
"url": "https://courseapi-spring-boot.herokuapp.com/beans",
295316
"method": "GET",
296317
"header": [],
297-
"body": {},
318+
"body": {
319+
"mode": "raw",
320+
"raw": ""
321+
},
322+
"description": ""
323+
},
324+
"response": []
325+
}
326+
]
327+
},
328+
{
329+
"name": "Swagger - Document APIs",
330+
"description": "",
331+
"item": [
332+
{
333+
"name": "API-Docs",
334+
"request": {
335+
"url": "https://courseapi-spring-boot.herokuapp.com/v2/api-docs",
336+
"method": "GET",
337+
"header": [],
338+
"body": {
339+
"mode": "raw",
340+
"raw": ""
341+
},
342+
"description": ""
343+
},
344+
"response": []
345+
},
346+
{
347+
"name": "Swagger UI",
348+
"request": {
349+
"url": "https://courseapi-spring-boot.herokuapp.com/swagger-ui.html",
350+
"method": "GET",
351+
"header": [],
352+
"body": {
353+
"mode": "raw",
354+
"raw": ""
355+
},
298356
"description": ""
299357
},
300358
"response": []

CourseAPI-Spring-Starter.md

Lines changed: 79 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,85 @@ Visit below address to see all the latest changes for these files.
782782

783783

784784

785+
### Actuator - Monitoring App
786+
787+
Monitoring our app, gathering metrics, understanding traffic, or the state of our database become trivial with this dependency. Actuator is a production-grade monitoring tool
788+
789+
Actuator is mainly used to **expose operational information about the running application** — health, metrics, info, dump, env, etc. It uses HTTP endpoints or JMX beans to enable us to interact with it.
790+
791+
Adding to ***POM.xml***
792+
793+
```xml
794+
<dependency>
795+
<groupId>org.springframework.boot</groupId>
796+
<artifactId>spring-boot-starter-actuator</artifactId>
797+
</dependency>
798+
```
799+
800+
**Actuator Links**
801+
802+
```json
803+
http://localhost:8080/actuator
804+
http://localhost:8080/actuator/health
805+
http://localhost:8080/beans
806+
```
807+
808+
809+
810+
811+
812+
### Swagger (Documentation Tool)
813+
814+
Swagger is an Interface Description Language for describing RESTful APIs expressed using JSON. Swagger is used together with a set of open-source software tools to design, build, document, and use RESTful web services. Swagger includes automated documentation, code generation, and test-case generation. It used for -
815+
816+
- Develop APIs
817+
- Interact with APIs
818+
- Swagger UI - Document APIs (Most Important feature)
819+
820+
821+
822+
**Adding Swagger to Spring Boot**
823+
824+
- Getting swagger 2 Spring Dependency. For now, we need to use Spring boot 2.5.2 , else it will give error in runtime.
825+
826+
```xml
827+
<parent>
828+
<groupId>org.springframework.boot</groupId>
829+
<artifactId>spring-boot-starter-parent</artifactId>
830+
<version>2.5.2</version>
831+
</parent>
832+
...
833+
<!-- Production Grade API Documentaion Tool -->
834+
<dependency>
835+
<groupId>io.springfox</groupId>
836+
<artifactId>springfox-swagger2</artifactId>
837+
<version>2.9.2</version>
838+
</dependency>
839+
```
840+
841+
842+
843+
- Enabling Swagger in code
844+
845+
```java
846+
@SpringBootApplication
847+
@EnableSwagger2 // Enabling Swagger so that it can run
848+
public class CourseApiApp {
849+
public static void main(String[] args) {
850+
SpringApplication.run(CourseApiApp.class, args);
851+
}
852+
}
853+
```
854+
855+
856+
857+
Now you can access swagger at : http://localhost:8080/swagger-ui.html
858+
859+
- Configuring Swagger
860+
- Adding Details as annotations to APIs
861+
862+
863+
785864

786865

787866
### Packaging Production Ready App
@@ -814,31 +893,6 @@ $ java -jar target/CourseAPI-Spring-Starter-0.0.1-SNAPSHOT.jar
814893

815894

816895

817-
### Actuator - Monitoring App
818-
819-
Monitoring our app, gathering metrics, understanding traffic, or the state of our database become trivial with this dependency. Actuator is a production-grade monitoring tool
820-
821-
Actuator is mainly used to **expose operational information about the running application** — health, metrics, info, dump, env, etc. It uses HTTP endpoints or JMX beans to enable us to interact with it.
822-
823-
Adding to ***POM.xml***
824-
825-
```xml
826-
<dependency>
827-
<groupId>org.springframework.boot</groupId>
828-
<artifactId>spring-boot-starter-actuator</artifactId>
829-
</dependency>
830-
```
831-
832-
**Actuator Links**
833-
834-
```json
835-
http://localhost:8080/actuator
836-
http://localhost:8080/actuator/health
837-
http://localhost:8080/beans
838-
```
839-
840-
841-
842896
### Hosting in Heroku
843897

844898
Heroku is a popular platform for hosting all types of applications. There is a Free plan for personal projects also.

0 commit comments

Comments
 (0)