RESTful API - Spring Data JPA

Slack Discussion Repositories https://github.com/terawarehouse/terawarehouse-catalog https://github.com/terawarehouse/terawarehouse-react Hi...



Slack Discussion

Repositories
Hi! Again this is Edward, I hope you learn new things from me as we go along these set of videos. If you find my videos useful, please don’t forget to subscribe to my youtube channel.

We are now in the final video for this set on REST API. And this will be about the Spring Data JPA. Which is a Spring dependency that lets us exposed REST services from the repositories we have in our project. Remember, in our earlier presentations we have created an endpoint for the category at /v1/categories.

Before opening the HAL browser, it’s common to change the URL by adding an API suffix, so let’s open the application.properties file and add the configuration below.

[open application.properties]

spring.data.rest.base-path=api

[open the browser, navigate to http://localhost:8080/api]

We should be able to see the list of available repository endpoints from our project like categories, products, dealers, etc. And you can play with these endpoints in the HAL browser, figuring out the parameters.

Another important thing to remember is that we can exclude a repository in the auto-generated endpoints if we want to, we just need to annotate the repository with @RepositoryRestResource(exported = false). In case it’s the method we want to exclude, just override that method and annotate with @RestResource(exported = false).

[open BrandRepository class]

And finally, to enable Swagger documentation we need to add the following dependencies in the project’s pom file.

<properties>
<springfox.version>3.0.0-SNAPSHOT</springfox.version>
</properties>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-data-rest</artifactId>
<version>${springfox.version}</version>
</dependency>

Unfortunately, the previous version of Swagger (2) doesn’t work on the version of Spring booth we are using so we will be making some changes on the Swagger config class.

[open SwaggerConfig class]

Change the annotation from Swagger2 to

@EnableSwagger2WebMvc
@Import({ SpringDataRestConfiguration.class })

And that’s it for this section. Next, we will start working on a microservice architecture or possibly our client app which will be in React. Which do you prefer? I hope you and joy and keep learning!

COMMENTS

mas template
Name

amazon,1,angular,8,bigdata,2,business,1,course-spring,27,courses,6,database,4,docker,3,java,50,kafka,1,keycloak,4,microservices,5,mysql,1,neworking,1,nosql,2,php,1,pinned,2,react,3,server management,7,shared drive,1,spring,7,synology,1,troubleshooting,2,web,1,wordpress,1,
ltr
item
toztech: RESTful API - Spring Data JPA
RESTful API - Spring Data JPA
https://i.ytimg.com/vi/21wHevbxXAA/0.jpg
https://i.ytimg.com/vi/21wHevbxXAA/0.jpg
toztech
https://toztech.blogspot.com/2019/08/restful-api-spring-data-jpa.html
https://toztech.blogspot.com/
https://toztech.blogspot.com/
https://toztech.blogspot.com/2019/08/restful-api-spring-data-jpa.html
true
2554149350007112447
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content