I want to know whether PostgreSQL provides support for rest or is there any other way to achieve it?
-
3PostgreSQL is an RDBMS, it has nothing to do with REST! But it has JDBC drivers available, so use such a driver with a Java API which does REST and you're set. Strange question, really. After that, which Java ORM (hint: use JooQ) and REST-able API you use is up to youfge– fge2015-01-08 05:58:35 +00:00Commented Jan 8, 2015 at 5:58
3 Answers
Another project that try to solve this is PostgREST. It's written in Haskell not Java, but you can use it from Java using ordinary HTTP requests.
PostgREST serves a fully RESTful API from any existing PostgreSQL database. It provides a cleaner, more standards-compliant, faster API than you are likely to write from scratch.
Postgres doesn't support an REST interface out of the box. But there is an early draft about adding one: Postgres Wiki So Postgres might add one in a future version. There are some "experiments" for it on Github: link
Right now there are two viable solutions:
Use a third party tool, that provides a rest api for postgres. restsql would be an example.
Implement your own Webservice layer.
It depends on your requirements which way to go:
(2) offers you the most control. You can design the api the way you need it. Modern Java Frameworks (JPA, JAX-RS, Jackson etc.) make it fairly easy and efficient to create a lightweight API layer.
(1) would be viable if you only need a basic way to access a DB over REST.
Comments
Disclamer: I am an owner of the product in the answer.
Hello,
You might want to check out https://zenite.io, a database host platform that supports REST endpoints for querying the database data.
For example, you can create an API endpoint /user and define a SQL query on it:
SELECT * FROM users WHERE id = $id;
and then execute a GET request on the database server:
https://server.zenite.io/user?id=1
This URL would return the data in the JSON format:
[
{
"rows": [
{
"Id": 1,
"FirstName": "John",
"LastName": "Doe",
"Age": 30
}
],
"code": 0
}
]
The supported technologies include PostgreSQL, among others.