RESTful-style Web services Framework Swagger

Source: Internet
Author: User

Swagger is a normative and complete framework for generating, describing, invoking, and visualizing RESTful Web services. The overall goal is to have the client and the file system update at the same speed as the server. File methods, parameters and models are tightly integrated into the server-side code, allowing the API to always stay in sync. Swagger making deployment management and using powerful APIs has never been easier.

    1. Create a project

1.REST API

  1. Import Javax.ws.rs.Consumes;
  2. Import Javax.ws.rs.GET;
  3. Import Javax.ws.rs.POST;
  4. Import Javax.ws.rs.Path;
  5. Import Javax.ws.rs.PathParam;
  6. Import javax.ws.rs.Produces;
  7. Import Javax.ws.rs.core.MediaType;
  8. Import Com.wordnik.swagger.annotations.Api;
  9. Import com.wordnik.swagger.annotations.ApiOperation;
  10. @Path ("/user")
  11. @Api (value = "/user", description = "User REST for Integration testing")
  12. Public interface UserService {
  13. @GET
  14. @Path ("/getuser/{username}")
  15. @Consumes (Mediatype.application_json)
  16. @Produces (Mediatype.application_json)
  17. @ApiOperation (value = "Get User Details", response = user. ) Class)
  18. Public User GetUser (@PathParam ("username") String username);
  19. @POST
  20. @Path ("/saveuser")
  21. @Consumes (Mediatype.application_json)
  22. @Produces (Mediatype.application_json)
  23. @ApiOperation (value = "Save User Details", response = user. ) Class)
  24. Public user getUser (user user);
  25. }

2.Swagger Config

  1. <!–swagger API Listing resource–>
  2. <Bean id="Swaggerresourcejson"
  3. class="Com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON" />
  4. <!–swagger writers–>
  5. <Bean id="ResourceWriter"
  6. class="Com.wordnik.swagger.jaxrs.listing.ResourceListingProvider" />
  7. <Bean id="Apiwriter"
  8. class="Com.wordnik.swagger.jaxrs.listing.ApiDeclarationProvider" />
  9. <jaxrs:server address="/SW" id="swagger">
  10. <Jaxrs:servicebeans>
  11. <ref bean="Swaggerresourcejson" />
  12. </Jaxrs:servicebeans>
  13. <jaxrs:providers>
  14. <ref bean="ResourceWriter" />
  15. <ref bean="Apiwriter" />
  16. </jaxrs:providers>
  17. </jaxrs:server>
  18. <Bean id="Swaggerconfig">
  19. <property name= "resourcepackage" value="Com.xymiyue" />
  20. <property name="version" value="2.0″ />
  21. <property name= "basepath" value="Http://localhost:8080/SwaggerUI-Integration/rest" />
  22. <property name="title" value="Swagger UI integration Sample" />
  23. <property name="description"
  24. value="Swagger UI integration Sample for demonstrating it working." />
  25. < name="Contact" value="[email protected]" />
  26. <property name="Scan" value="true" />
  27. </Bean>

3.Swagger UI

UI page Reference Https://github.com/Duttor/swagger-ui

Reference Example Project:

Https://github.com/saurabh29july/SwaggerUI-Integration

http://wangbaocai.cn/?p=1204

RESTful-style Web services Framework Swagger

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.