Giter Site home page Giter Site logo

api-paths's Introduction

Rest Api All Operations

I developed a component that lists the operations in API.

@Component
public class AppPathComponent {

@Autowired
WebApplicationContext applicationContext;

@Autowired
private RequestMappingHandlerMapping requestMappingHandlerMapping;

public List<Operation> getApiPaths() {

    List<Operation> operations = new ArrayList<>();
    Map<RequestMappingInfo, HandlerMethod> map = requestMappingHandlerMapping.getHandlerMethods();
    for (Map.Entry<RequestMappingInfo, HandlerMethod> m : map.entrySet()) {

        Operation operation = new Operation();
        RequestMappingInfo info = m.getKey();
        HandlerMethod method = m.getValue();
        PatternsRequestCondition p = info.getPatternsCondition();

        for (String url : p.getPatterns()) {
            operation.setUrl(url);
        }

        operation.setClassName(method.getMethod().getDeclaringClass().getName());
        operation.setMethod(method.getMethod().getName());

        RequestMethodsRequestCondition methodsCondition = info.getMethodsCondition();
        String type = methodsCondition.toString();
        if (type != null && type.startsWith("[") && type.endsWith("]")) {
            type = type.substring(1, type.length() - 1);
            operation.setType(type);
        }
        operations.add(operation);
    }
    return operations;
}

Result

    [
        {
            "url": "/products/addProduct",
            "method": "addProduct",
            "className": "com.kubilaycicek.product.rest.ProductController",
            "type": "POST"
        },
        {
            "url": "/products/updateProduct/{id}",
            "method": "updateProduct",
            "className": "com.kubilaycicek.product.rest.ProductController",
            "type": "PUT"
        },
        {
            "url": "/error",
            "method": "error",
            "className": "org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController",
            "type": ""
        },
        {
            "url": "/products/product/{id}",
             "method": "getProduct",
             "className": "com.kubilaycicek.product.rest.ProductController",
             "type": "GET"
        },
        {
            "url": "/products/list",
            "method": "getList",
            "className": "com.kubilaycicek.product.rest.ProductController",
            "type": "GET"
         },
         {
            "url": "/error",
            "method": "errorHtml",
            "className": "org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController",
            "type": ""
         },
         {
            "url": "/products/product/delete/{id}",
            "method": "deleteProduct",
            "className": "com.kubilaycicek.product.rest.ProductController",
            "type": "DELETE"
          },
          {
            "url": "/getAllApiPaths",
            "method": "getAllApiPaths",
            "className": "com.kubilaycicek.product.rest.ApiController",
            "type": "GET"
           }
]

api-paths's People

Contributors

kubilaycicek avatar

Stargazers

Furkan ŞAHİN avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.