Creating a RESTful WebService without using Jersey or any other libs

后端 未结 2 982
生来不讨喜
生来不讨喜 2021-02-07 23:48

okay you might say its a duplicate of this.

It might be but the answer is still yet to be found.

Isn\'t there any way we can make a RESTful web service without u

相关标签:
2条回答
  • 2021-02-08 00:32

    If you want to use JAX-RS, which is a specification, you must use an implementation of this specification. Jersey is the Reference Implementation of JAX-RS but any other implementation is fine, too.

    You can write a service with a RESTFul interface using plain Servlets. But why reinvent the wheel? You really don't want to do this. But if you must, read the Java EE Tutorial on Servlets. But a Servlet will not be RESTFul without further work. You can easily fall into the trap of writing a RPC-style service.

    0 讨论(0)
  • 2021-02-08 00:42

    You should be able to accomplish this with servlets. Create a servlet for each service or url that you expose to your service consumers.

    Eg. For a user CRUD service, create a UserServlet and specify the mapping as /user/*. Consumers of your service, will hit urls such as

    • http://yourdomain.com/user
    • http://yourdomain.com/user/23

    for various RESTful operations.

    Inside of the servlet, you should be able to extract the request parameters, form data, request headers and context information.

    For a detailed discussion on how to design your restful api and best practices, search "Restful API Design". Here are a couple of links to get you started

    • https://blog.apigee.com/detail/api_design_third_edition_video_slides
    • https://blog.apigee.com/detail/slides_for_restful_api_design_second_edition_webinar/
    0 讨论(0)
提交回复
热议问题