How to create/build REST URI using form parameters

后端 未结 1 459
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-28 12:19

okay so i have created restful webservice.now how to create a path for a user \"abc\".
Something like this

http://stackoverflow.com/user/abc
相关标签:
1条回答
  • 2021-01-28 13:07

    Use the @Path and @PathParam annotations:

    @Path("/user/{uname}")
    @PUT
    @Consumes("text/plain")
    public void putUser(@PathParam("uname") String uname, String password) {
      // ..
    }
    

    If you PUT to /user/joe with a body of s3cret, then uname will be joe and password will be s3cret.

    I use PUT because the URL you want to use implies that the username is set by the client. /user is the collection resource of all users.

    Edit: Since this method will change the server state by creating a new user, PUT or POST must be used. GET must not change the server state.

    0 讨论(0)
提交回复
热议问题