I have to automate certain operations of PUT/POST operation in my case, I have those endpoints already-in-place which will do their part.
My planning is to have another method which will drive this whole automation, consider this method as new POST endpoint which would gonna call each either POST and PUT endpoint from the same service which I already mentioned.
I will gonna call those existing PUT and POST based on input, if consider the input is new I will call existing POST and if given input exists in database I will going to call PUT.
Till I am good, But I have a question in my mind, Which is bugging me a lot that my new endpoint which is of POST is calling PUT as well as POST, I each method type has to do its type of operations only but here I am calling PUT as well as POST whereas my parent calling method type is POST.
I am not sure if I am working in right direction to achieve my use-case.
Please correct me in a different way.
Note - I am having Spring Boot application which would always need some endpoint to trigger any logic which I am talking about.
Update my question for better understanding.
I dont really know what you mean exactly. The HTTP methods are considered to do a specific task, but yet again its ok to use POST to update something - might be not best practice, but works. If you want to seperate the concerns (adding, updating), then just implement two different endpoints, one handling the creation the other one the update. The client (whether its a web-app or desktop app or whatever) has to handle this issue.
Related
I am bit confused, whether I should validate the data returned from the remote call to another Microserivce Or should I rely on the contract between these Microservice.
I know putting extra checks will not hurt anyone but I would like to know what's the right approach?
in theory, you don't even know how the data you get back from a microservices is created since you only know the interface (API) and what it is returning.
By that, you should take the data response of this API as given.
Sure, additional validation may not harm in the first place.
But consider a case where some business-logic got changed which lead to a change in one of the services. Could be a simple thing like adapting the definition of a KPI leading to a different response (datawise, not structurewise) from the microservice.
Your validation would fail too as false-positive. You would need to adapt your validation for basically nothing.
I'm new with Retrofit. My current solution is to call first webservice and in OnResponse override, call second one, providing result from first call as parameter to second call.
Finally, I need an object containing data loaded from both webservices called. My solution actually works. However, I'm not satisfied with it. Code is not clean and terrible to maintain (I will also need 3 webservices chain).
I've heard something about RxJava and flatMap method. Can anybody point me right direction? Complete code sample/turorial (including Retrofit intrerfaces definition) would be very helpful. Partial code samples I have already found is not something easy to understand, so I'm stuck now.
Thanks and sorry for possible duplicate.
I have a pretty simple purpose
URIs of form ->/random/* go to /*. For example /random/users goes to /users.
I don't wish to use redirect() to solve the problem.
I have a tried a few ways but not sure about implementation -
Intercept the request before it reaches the router. And change the URI somehow. I am trying to Override the onRequest method, but unable to proceed as I don't know the implementation. (possible issue with: should routing really be here?)
Have an entry in routes which is like /random/*, make it point to a controller method. From inside the controller call the router method again with the modified URI. Again here unable to proceed as stuck with implementation.
Double the routes file or put a regex in routes file. For each entry, copy it and append /random to it. I dont want to do this, since it makes the file difficult to manage. Last resort really.
Please help regarding how to implementation Point 1 or Point 2.
If there is any other much simpler way please help..
Add a new Random-controller and create an action which forwards the calls to the proper controllers.
Use the following route:
GET /random/:controller controllers.Random.handleRandom(controller:String)
Let the handleRandom-action forward the calls accordingly (with or without redirect). You can either do some reflection-magic to forward the call to other controllers, or use a if-then-else- or switch-clause.
I have some a java portlet application which calls a restful service. I have struck a problem where it looks like I am coming across a threadsafe issue. I have a servlet specifically used for Ajax calls. This servlet is called from myultiple locations at the same time.
It looks like my application is getting confused because the Ajax servlet is receiving multiple requests from different locations at the same time. I didn't think that this would be a problem.
Can someone help me understand the issue and secondly suggest a way to fix/improve? I think I will struggle to put a code snippet here because it will be too large to demonstrate the issue.
But basically the pattern is that I fire some 2 ajax requests from javascript to a servlet at the same time with different parameters. The handling of the servlet request is different based ont he different parameters passed in. But they both call the same java static methods to handle creating json objects. And it's those static methods that look like they are getting confused.
When I'm printing debug messages in the static methods the static methods show the debug info from the first call and then the static methods start showing debug info from the second call before the first is finished.
thanks for the help and sorry for no code snippet (probably too long)
All you need is to check if there are methods that using same non-threadsafe resources (i.e. HashMap in the field, or something). If there are, add locks or get rid of these fields (make them local).
As per RESTful services guidelines we should use GET for reading a resource, POST for creating a new resource, DELETE for deleting an existing resource etc.
But assume I am developing a RESTFul webservice, say OrderProcessing. In placeOrder(Order) method I have to read some tables like inventory, product details etc, insert some new rows into tables like order and order details and do updates like reducing the inventory level etc. Then what HTTP method should I use for placeOrder() method.
At the very high level we are creating a new resource(Order), so I thought POST is correct HTTP method to use.
But in general what verb should be used for method doing read/create/update of data inside same method?
I agree with your thinking that POST is appropriate here. Even though you are doing multiple operations, you can view this as a single create of your Order resource. As for the other operations, I would view those as internal details that you are not exposing to the consumer of your service.
Edit - Taking this a step further, This assumes that you have defined Order as your resource, and the POST body contains a representation of this resource. And to be totally RESTful, if the POST results in the creation of a new Order, then HTTP 201 is the appropriate response code. See section 9.5 of http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html for more details.
Definitely POST. You can rule out GET and DELETE for obvious reasons, and you would only want to use PUT for an idempotent operation. Since you're reducing inventory, you can safely rule out PUT as a viable option.