In: Categories » » AJAX » Ajax Closed Access Web Services
With the creation of REST-based Web services and their ability to store and retrieve data comes the question of how to store data. In a SQL database, you can use the SQL SELECT to query the database and generate a result set. That’s what you’re doing for 90% or so of the database operations and the Web.
However, to be able to query a database or Web site, you have to have data to query or browse. This raises the question of how to put the data into the Web. In the case of the database, the answer is easy: you execute SQL statements, and data is stored in the database. However, it is possible to use C and some file operations to add entries into the database. Well, at least that is theoretically possible. The problem is that companies such as Oracle, Microsoft, and IBM aren’t going to tell you how their files are structured. That lack of documentation is the decision maker of whether you use REST to store data, or whether you use background processes. The database vendors aren’t going to allow you to add data to their database using C file operations, because you would corrupt the database. Whenever you execute a SQL insert statement, a whole host of things happen (such as indexing and optimization) that wouldn’t occur if you accessed the database directly. Let’s go back to the original question: Should REST-based Web services be closed access? The answer is yes, whenever possible. For example, it might not be possible when you’re dealing with legacy applications such as the blogging application.
You want a REST-based Web service to have closed access, because it is your nextgeneration data source. Relational databases are wonderful persistence tools, but they have their limits, especially in the context of Internet-based applications. You could use objectoriented databases, but they haven’t caught on for one reason or another the reality is that most data is stored in relational databases. With REST-based Web services, you want to encapsulate the logic on the server and expose a set of URLs that represent Web service operations.
Article Summary This article illustrated how to build universal Web services using REST-based techniques. Remember the following points:
• You should treat Web services as components and only implement the functionality necessary.
• As the example illustrates, you don’t need to componentize the Web service. That doesn’t mean that componentization is not necessary, nor does it mean that you should ignore good object-oriented design principles. It does mean that you don’t always need to componentize, and you should consider the Web service boundary as part of your componentization.
• Only create code components when it makes sense. The aim is to componentize your application using Web services.
• Your Web service will be a success based on its interface and the usability of the interface, not on the code behind the interface. For example, if you need a fast response time, write code that is fast, even if that means using arrays instead of linked lists and so on.
• Using classes instead of components doesn’t mean that you cannot configure the behavior of your Web service. For example, you don’t have to hard-code the URLs used to define the Web service. Configurability and componentization are two orthogonal issues.
• When defining the Web service, focus on the URLs and the data that the URLs accept and generate.
legal notice
Our website is not responsible for the information contained by this article. Web-articles is a free articles resource.
Suggestion: If you need fresh, daily updated content for your website, feel free to use our service. Click here for more information.
Useful tools and features
related articles
The Easiest Way to Get Started with Ajax and REST Problem You want to know the best way to get started with writing Ajax and REST. Solution When developing an Ajax and REST application, you must decide on the tools and frameworks you’ll use. The choice is simple: Use whatever you’re using today, and write some Ajax applications. You don’t need to change the tools you’re using today. Whether you’re using ASP.NET, JavaServer Pages (JSP), PHP, Ruby, or Python, you...
2. Testing a Dynamic Contract with Ajax
Coding the Contract Using Test-Driven Development Techniques Coding the contract using agile and test-driven development techniques requires writing a number of tests and implementing aMock URL layer. Problem You want to code the contract using these development techniques. Solution To demonstrate, let’s define a use case, implement the use case as a contract, write a test case(s) to implement the contract, implement the contract in the Mock URL, and finally...
3. Testing the Client Side Logic
Problem You want to effectively test your application’s client-side logic. Theory Testing GUI code tends not to be a productive task because of the complications that arise. The main complication is how to test the correctness of a user interface. Imagine a situation where clicking a button causes a table to be filled with data. Now imagine that when a check box is checked and the button is clicked again, a different table is filled with content. The fact that clicking the same button results in two ...
4. Understanding JavaScript and Types
Understanding JavaScript and Types Problem You want to work around the fact that JavaScript does not have types declared for its variables. Theory JavaScript code does not have any variables with a declared type. The lack of typed variables is apparent when you declare functions. That said, not having typed variable declarations does not mean JavaScript has no types or no type safety. Let’s start out with the simple declaration of a function, as illustrated by the following ex...
5. Coding Using Conventions and Not Configurations
Coding Using Conventions and Not Configurations Problem You want to make your JavaScript constructs more efficient by applying the Rails “convention over configuration” principle to them. Theory You may already be familiar with the programming platform Ruby on Rails, which is used to build Web applications. The focus of this recipe is not Ruby on Rails, but one aspect of Ruby on Rails namely, convention over configuration (see http://en.wikipedia.org/wiki/ Ruby_on_Rails for m...
6. Advantage of parameterless functions in JavaScript
Using Parameterless Functions Problem You want to take advantage of parameterless functions in JavaScript. Theory JavaScript functions for the most part have parameters. You may think that the previous sentence states the obvious after all, without parameters, what data could be passed to a function? JavaScript has the ability to declare functions that have no parameters, even though the caller of the function has passed parameters to the function. For example, let’s look at...
7. JavaScripot Functions
Treating Functions Like Objects Problem You want to take advantage of the fact that functions are objects (remember, everything is an object in JavaScript). Theory Many people think that a function is some keyword used in JavaScript. A function is also an object that can be manipulated. Knowing that a function is an object makes it very interesting from the perspective of writing JavaScript code, because the code can treat the function like another other object. This mean...
8. Implementing an Error and Exception Handling Strategy
Implementing an Error and Exception Handling Strategy Problem You want to implement a clean error and exception handling strategy in your applications, to make them run more smoothly. Theory Of course, you might argue that one error is a dialog box and the other is generated in the JavaScript console. The fact that one browser uses a dialog box to show an error and the other does not is a browser issue, not an error issue. A concise way of classifying the two errors is to ...
9. Understanding the Behavior of Variables When Implementing Recursion
Understanding the Behavior of Variables When Implementing Recursion Problem You want to implement recursion in JavaScript, and you also want to understand how variables will behave under those circumstances. Theory In JavaScript, you do not need to declare the variable type, or even declare the variable. For example, the following code works perfectly: if( counter == 1) { buffer = "counter is 1"; } document.getEle...
10. Using Functions to Initialize and Make Decisions JavaScript
Using Functions to Initialize and Make Decisions Problem You want to use functions to initialize and make decisions. Theory Usually when you write a piece of code where a change of logic needs to take place based on a context, you use a decision structure. For example, say you are implementing a light switch using a program. You turn on the light if the light is off, and you turn off the light if the light is on. The behavior of the program is determined by the conditions. One example behavior t...
