How-to articles, tricks, and solutions about REST

'Field required a bean of type that could not be found.' error spring restful API using mongodb

The 'Field required a bean of type that could not be found' error in a Spring application typically indicates that the application is trying to inject a dependency into a field, but it cannot find a bean of the required type in the application context.

How to build a RESTful API?

To build a RESTful API in PHP, you can use a framework such as Laravel or CodeIgniter, or you can build the API from scratch using core PHP.

How to get body of a POST in php?

To get the body of a POST request in PHP, you can use the file_get_contents function and pass it the special php://input stream.

How to POST form data with Spring RestTemplate?

To POST form data with the RestTemplate class in Spring, you can use the postForObject method and pass it a URL, an object containing the form data, and the response type.

JAX-RS — How to return JSON and HTTP status code together?

In JAX-RS, you can use the Response class from the javax.ws.rs.core package to return a JSON response and an HTTP status code together. Here's an example of how to do this:

Main differences between SOAP and RESTful web services in Java

SOAP (Simple Object Access Protocol) and REST (Representational State Transfer) are two different styles of web services that can be used to expose the functionality of a web-based system over the internet.

PHP cURL HTTP PUT

To make an HTTP PUT request using PHP's cURL functions, you can use the following snippet:

POST request via RestTemplate in JSON

To make a POST request with the RestTemplate in JSON, you can use the postForObject() method and pass it the URL of the request, the request body, the response type, and the HttpEntity object that represents the request headers and body.

RESTful call in Java

To make a RESTful call in Java, you can use the HttpURLConnection class.

Spring MVC - How to return simple String as JSON in Rest Controller

To return a simple string as JSON in a Spring MVC Rest Controller, you can use the @ResponseBody annotation and return the string directly.

Spring RestTemplate GET with parameters

To perform a GET request with parameters using the RestTemplate in Spring, you can use the getForObject() method and pass it a URL with placeholders for the parameters, as well as a map of the parameter values.

When to use @QueryParam vs @PathParam

In a Java RESTful web service, the @QueryParam annotation is used to bind a query parameter to a method parameter, while the @PathParam annotation is used to bind a path parameter to a method parameter.