Using Sqlrest to convert a database to a RESTful Web service

Source: Internet
Author: User
Tags db2 representational state transfer tomcat

With the development of Web 2.0, rest (representational state Transfer)-style web Service has been widely used and various rest frameworks have sprung up. When we are engaged in the practice of Web 2.0, it is increasingly felt that the server-side REST service has great problems in dealing with mis-like information systems as well as interacting with the database, such as inefficient, repetitive coding and so on.

For example, we assume the scenario that requires the use of WEB 2.0 technology to implement an information management system, the primary task of which is to operate, manage, and report on the business data of the backend database. Such scenarios are common in business systems such as finance. We can use entity beans to implement EJBS, then wrap that EJB into rest services, or use lightweight Hibernate with a variety of Java REST frameworks, but it's inevitable that you need to do a lot of repetitive coding or implement a lot of database operations. Since REST regards service as a service of resources, we can assume that the data in the database is also a resource. Is there a way to translate them directly into REST services? Sqlrest is a framework that is a highly efficient, lightweight database rest service solution that exposes data in a database to RESTful WEB services directly, and makes CRUD operations of the database and rest services get, DELETE, POS T, the Put interface corresponds.

This article describes the configuration and operation of this framework, discusses how to test the rest service, and finally gives a reference to configuring DB2 to implement DB2 resources in the WEB 2.0 and Rest service developers. The example in this article uses TOMCAT 5.5 based on the Eclipse 3.2 and Jdk1.5,servlet containers.

Sqlrest First Step

Download and run

Sqlrest is an open source project on the SourceForge site that uses a Servlet to implement a database-based REST engine that automatically maps the tables of the database to rest resources, using the URL to get the contents of the table (XML format) and doing the relevant 。

We first download a binary package to run the Sqlrest sample. You can access the project through http://sourceforge.net/projects/sqlrest/. On the first page, click on the download, go to the download page to download the sqlrest-0.3.2 version, which is currently the only available version.

After downloading, please confirm that JRE 1.4.1 and TOMCAT version 4.1 are installed. Copy the Sqlrest directory in the WebApps directory in the uncompressed directory to the TOMCAT WebApps directory. Start TOMCAT, type http://localhost:8080/sqlrest in your browser (if your TOMCAT port is 8080), you will see the Sqlrest Web interface as shown in Figure 1:

Figure 1. Sqlrest Initial Web interface

This page describes 4 of the available REST resources in the database, which means that the installation is successful and we can begin to work further.

The reader needs to be aware that, depending on the JRE version and type, it is possible for TOMCAT to fail at startup (refer to the error message shown in Figure 2), and the sqlrest Servlet cannot load, causing the error because the sqlrest we downloaded was a binary version and compiled sqlrest There is an incompatibility between the JRE and the JRE we are running Tomcat. The solution is to get the source of the sqlrest, recompile in the running environment, and then copy the compiled class file to the classes directory in the Webapp/sqlrest/web-inf directory in Tomcat to restart it. If you choose to start compiling and deploying from the source project, you can avoid this error (TOMCAT and Eclipse use the same JRE), and you'll see how to get the code from CVS and start compiling the deployment sqlrest from the source.

Figure 2. Startup errors caused by compatibility problems with different JDK

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.