How force PUT request from a POST with Spring? - spring

I have a service with routes on PUT and I want to make a SDK implementing those routes in Unity3D. The problem is WWW don't accept PUT request.
The service is based on Spring Framework.
From the SDK, I try to call the route in POST with an additional parameter _method set to PUT but it doesn't work.
There is a way to simulate a PUT request with a POST call in Spring Framework?
Thanks in advance for your help.

Have you configured HiddenHttpMethodFilter filter in your springframework, its required at server side to convert post request with _method parameter to put request

Related

Need to change GET mapping name on Swagger UI

I am working with Java Spring Boot Application.
My Current GET method in RestController is below .
GetMapping on RestController
After launching my swagger looks like below
Swgger UI
Is there any way, i can still use "/v1/person" in Controller , but on swagger i only want to display "/person".
I don't want "/v1/person" on swagger
Firstly, It is not possible to do that.
I think you are looking at it completely wrong. Swagger is meant to be like a contract that you expose to the client(who ever is calling your API). This should have details about what the endpoint is all about, how a client can call your endpoint, with what arguments and what the client can expect in return.
If you use /v1/person in your controller, that means it can only be called with url http://......./v1/person.
Now if you (somehow) display /person in Swagger, then the client cannot call your endpoint and the basic idea of Swagger is destroyed.
Hope its clear.

What is the differences between Spring Boot API without Filter and Spring Boot API with Filter?

From the beginning, I often write Spring Boot API with many API depend on what my application needs. I know there is a type like Filter Servlet, what is it? Can anyone help me to find the difference between API with Filter and without Filter?
I have go through some research: https://www.baeldung.com/spring-boot-add-filter and https://www.tutorialspoint.com/spring_boot/spring_boot_servlet_filter.htm
I have a sample for using Servlet Filter: https://help.shopify.com/en/api/reference/products/product#create-2019-10
A filter is an object used to intercept the HTTP requests and responses of your application. By using filter, we can perform two operations at two instances −
Before sending the request to the controller
Before sending a response to the client.
so its depends on requirement of your app if you need to do some work before sending request to controller or not.
Take an example below:
if we need to create an application where we need to authenticate and authorization of user with help of token so in each api we need to verify token before sending request to controller so we can use filter their.
and sending response back to client if we want to append some token then we can add same in filter.
example of filter:
https://www.javadevjournal.com/spring-boot/spring-boot-add-filter/
below method use for next call:
filterChain.doFilter(request, response);

Is it possible to create a proxy controller that ignores some part of the URI

I have a spring service with multiple controllers with following request mapping running on port 9000
/api/fruits
/api/vegetables
/api/plants
Given all these requests are being served at localhost:9000,is it possible via some Spring entity, that a request to localhost:9000/{Account_id}/api/fruits is routed to localhost:9000/api/fruits. I know the question is a little vague but I'm trying to see if I can add a proxy controller with mapping /{account_id}/ which ignores the rest of the uri and have some code there to forward it to the appropriate controller. Not sure if Spring interceptor or filter of some sort would be helpful here for me to modify the request and change the URI

Pass variable from VueJS to Controller of another application

i have to application:
Back-end : with spring boot run on localhost:8080
Front-end : contain vueJs run on localhost:8081
i want to pass a variable from my front-end vueJs and read it in the back end spring boot, any help? thx
Just do an XHR request like you would to contact any server.
Sharing data between Frontend and Backend requires a communication channel. Most popular way is to write a GET/POST API into the server and make a REST call from the client.
You need to write an API in spring boot server (Ex: http://localhost:8080/INeedData )
Make XHR or Axios or HTTP GET/POST request from VueJS passing the variable as Body to the API
Refer:
https://www.journaldev.com/21127/spring-boot-rest-example
https://alligator.io/vuejs/rest-api-axios/

Emails in restful spring Get request url

I am having a problem with passing emails in http url using spring. My url looks as follows
http://localhost:8080/users/{email}
I am using spring mvc to handle this GET request.
Using my browser url bar or using Postman when I do the following
http://localhost:8080/users/sampleEmail#gmail.com
I only see sampleEmail#gmail in the spring controller code. For some reason the ".com" part is stripped out. Would anyone know if I am doing something wrong? Thanks
It is because Spring truncates whatever is coming after DOT(.) assuming it to be an extension.
Refer this:
Spring MVC #PathVariable with dot (.) is getting truncated
Is there a requirement that you need to use only GET? If not then switch to POST and send JSON Object with required parameters such as {email: "abc#xyz.com"}

Resources