How to make a URI which passes two parameters using restlet : Restlet 2.1 - restlet

This is an example of a method:
updatePatientAddressByID(String ID, String address)
Any Help

You have to design your URL so that the Id is a path segment :
router.attach("/patients/{id}", PatientResource.class);
Then in your Restlet implementation, you can get this variable :
#Post
public void store(String address) {
Long id = (Long) getRequest().getAttributes().get("id");
... do something with address ...
}

Related

what is the usage of name Property in HttpGet ( such as [HttpGet("/products2/{id}", Name = "Products_List")])

In asp.net core, I seen
[HttpGet("/products2/{id}", ***Name = "Products_List")]***
public IActionResult GetProduct(int id)
{
return ControllerContext.MyDisplayRouteInfo(id);
}
what is the usage of name Property in HttpGet (such as[HttpGet("/products2/{id}", Name = "Products_List")])
And, How Can I read/send a Multipart/form-data from/to an apiapicontroller/client?
Yes, it can be used like this. The second parameter of Url.Link is an object.
#Url.Link("Products_List", new { id = 1 })
Also this property RouteUrl can use it.
#Url.RouteUrl("Products_List",new { id=2})
About route name, this is the official introduction:
The route names give the route a logical name. The named route can be used for URL generation. Using a named route simplifies URL creation when the ordering of routes could make URL generation complicated. Route names must be unique application wide.
Route names:
Have no impact on URL matching or handling of requests.
Are used only for URL generation.
If you send a Multipart/form-data. The apicontroller can get it with FromForm.
[HttpGet("routepath")]
public IActionResult get([FromForm]SampleModel model)
{
//...
}
I found that can be used to string uri = Url.Link(“ Products_List”, id = 1);
Is there Some one can give me more detailed information?

Spring SpEL to set RequestMapping path with a list

I want to programmatically set the paths on a rest service. I have this bean method which has all the paths.
public List<String> getSubscribeChannelsForRest() { .. }
This is the rest service
#RestController
public class RestMessageController {
#PostMapping(
path = { "#{somebean.getSubscribeChannelsForRest()[0]}",
"#{somebean.getSubscribeChannelsForRest()[1]}",
"#{somebean.getSubscribeChannelsForRest()[2]}"
})
public String processMessage(#RequestBody String messageBody, HttpServletRequest request) { .. }
The above code works but I want to avoid hard coding the array numbers. There is what I tried.
#PostMapping(
path = { "#{somebean.getSubscribeChannelsForRest()}",
This doesn't work because the spring method RequestMappingHandlerMapping.resolveEmbeddedValuesInPatterns(String[] patterns) takes the above SpEL as a single element array. I've checked the trace logs and all the element in the given list get concatenated .

How can I get the value from #QueryParam

Basically what I'm trying to do is edit an entity that's stored in my db. For that I have a little method that is trying to access a paramater that's defined with #PathParam. My problem is that it comes back as null. Here is my method:
#PUT
#Path("/{id}")
#Produces(MediaType.APPLICATION_JSON)
public Response edit(#PathParam("id") Long id, #QueryParam("myParam") String name)
{
return Response.ok().build();
}
I`m using Postman to send the parameter to my server. My URL looks like this:
http://localhost:8080/myApplication/rest/users/1?myParam=test
How can I get the value from the parameter?
Try with
public Response edit(#PathParam("id") Long id, #QueryParam("myParam") String myParam) {
return Response.ok().build();
}
This will work. The query param and variable name will get auto bind if they are similar.

Getting the ID from the Route data in ASP.NET 5 API

I'm implementing an ASP.NET 5 API where I have the following POST method:
[HttpPost("{id}")]
public void Post([FromBody]string value)
{
// Do something
)
For me to process the request, I need both the ID and the string value which will be in the body.
I realize that I can also put the ID in the body but I was wondering if there's a way for me to get the ID directly from the route data -- like in MVC 4/5 where I'd use the following syntax:
var id = (string)this.RouteData.Values["id"];
What's the best way for me to get the ID value in ASP.NET 5? Use the code above or some other way?
You can decorate your parameter with [FromRoute]:
[HttpPost("{id}")]
public void Post([FromRoute] string id, [FromBody] string value) {
// Do something
)

How to get mapped path in jersey

Please refer following code. /hello/from/JohnDoe will hit the method sayPlainTextHello. When "/hello/from/JohnDoe" is accessed, I want to store the mapped path which is /hello/from/{name} in a log. Please note that I can't modify below code but can add filter, etc. to the app. How to get the mapped path "/hello/from/{name}" ?
#Path("hello")
public class GenericResource {
#GET
#Produces(MediaType.TEXT_PLAIN)
#Path("/from/{name}")
public String sayPlainTextHello(#PathParam("name") String fromName) {
return "Hello Jersey - " + fromName;
}
}