Convert custom API to Ruby on Rails ActiveResource - c++

I have a set of embedded devices that run software written in c++. The API to communicate the devices is simple: get/set/acquire parameters and signals.
I'd like to implement common web application to access all of the devices from a single point.
My idea was to add XML RPC interface to devices and then use ActiveResource to access devices from the web server. This combination doesn't seem to be used at all in practice.
I'm free to choose any protocol inside the devices. What are your recommendations?

If you're already considering XML RPC I'm assuming you have some sort of web server running on the device. I would probably choose a RESTful web service over XML RPC. If designed carefully you could have corresponding services on your Rails app.
For example:
http://somedevice/signals.json - gets all signals
http://yourrailsapp/somedevice/signals.json - gets somedevice's signals; you could use an id instead here if that makes more sense (http://yourrailsapp/devices/1/signals.json).

You probably won't find much XML RPC stuff in the Rails community. Rails itself really pushes you towards RESTful web services. Specifically a resource-oriented RESTful architecture. There are great books out there about it but it comes down to using http methods (get, put, post, delete) instead of passing parameters and then some intelligent URLS.

Related

SOAP or REST - when there is single client & multiple service providers + contract

We are using SOAP based web services to let end user schedule service appointments. Our portal is WebService client & we have a number of Vendors(who are spread across the globe in various timezones) who are building Webservice Server operations.
We are thinking to build it as a contract first SOAP based web services so that we have tight control(interface based e.g. date-time format should be standard xsd:dateTime etc.) over what can be sent & received as part of XML messages for possible success & error scenarios(via different error codes). We want to keep single client code for all the vendors. We would like to determine
1) Should we think about using RESTful web services?
2) Is there any way the vendors can use RESTful services also if they want at their end(by sticking to our WSDL contract) & we use SOAP at our end
First a little bit about,
REST (Representation State Transfer) is an architecture style to develop webservice. In which data and functionality are considered as a resource and can be accessed via URI (Uniform Resource Indicator). It follows client server architecture and uses stateless protocol (usually HTTP). Typically in REST webserivces resources are acted upon by GET, PUT, POST,DELETE operation. Generally we use JSON to exchange data between client and server. It is light weight.
On the other hand SOAP (Simple Object Access Protocol) is a XML based mesaage protocol. Which is generally used on enterprise level to define their own interfacing and operations as services. It also follows REST architecture.
So basically, it is a RESTful webservice.
Now to answer your question,
It seems you are going to expose your webservice client on enterprise level. Which is going to be used by many vendors to implement their own webservice server.
So, it is perfect, you go with SOAP webservices.
You will define the skeleton of the webservice like Message formats, Operations, binding etc which is called WSDL. It is widely used standard and very easy to understand by any third party. Something called WADL is used for REST services also but it is not very user friendly.
The same contract (WSDL) will be used by your vendors to implement the webservice on their server in Top to Bottom approach using some API, for example JAX-WS.
This way you will have a tighter control over your operations, formats, security etc. in a single contract (WSDL).
Now if a vendor wants to use REST webservice instead of SOAP. You can build a JAVA proxy on top of your client. Which will convert your soap messages into REST to send/receive request/response to REST webservices. But you can not dictate your contract in this approach. Although, You can recommend vendors to build their own proxy to handle your SOAP webservice requests. This way your contract will be intact.
If you are going to expose your webservice client for small applications then it is alright to go with REST but if you are an enterprise and going to expand in future, you should go with SOAP for robust features and easy maintenance.
Disclaimer: please do not consider this answer as really serious.
Well, I think question too abstract. Why do you asking it? Because you see yourself that currently everything is RESTful? Then you'r right. You can do any protocol. But if you will do REST with JSON instead of XML, everybody will thank you. And if you will use 40 years old technology for creating modern service, then probably not. Same for your contractors.
The only advantage SOAP seems to have in your situation is that it is already implemented.
SOAP is a complex standard with unfriendly implementation and verbose implementation - i.e. hard to work with and maintain. Also note that you are not even using it "by the book" since your security is external to it and not using ws-security
REST based interfaces would make your and your users' lives easier. I suggest you take a look at standards and tools like swagger for building APIs.If you're running on premise you can take a look at API gateways like tyk If you're running in the cloud you also take a look at AWS API Gateway

Servlet vs Webservices

Webservices like REST, SOAP which provides services which is made available for web application, as we know it can receives values as JSON, string, XML etc either by POST or GET and in the same way it can return data as JSON, string, XML etc.
The same thing can be done via servlet, as servlet can receive data as string, JSON etc either by POST or GET and in the same way it can return data as JSON, string, XML etc.
We need libraries based upon the web service we use, such as SOAP or REST, servlet libraries are almost in-built int it.
So whats the difference between Servlet and Web Services? Which one is more faster?
Can anyone please tell me some solution for this.
This is the kind of discussion that can lead to a lot of flame wars on semantics, but I would say web services are simply a method of communication utilizing standards to allow different technologies to be interoperable. Like an English-speaker translating between a French- and German-speaker.
Meanwhile, the way to implement web service endpoints (the places that serve responses to your requests) in a Java web server is with servlets. So servlets are simply a technology for implementing web service communication (in the JVM).
When you look at JAX-WS and JAX-RS, the frameworks that implement these standards are simply creating abstractions on top of Java's HttpServlet (typically) to make SOAP and REST web services easier to build by taking care of a lot of the low-level details.
Hope that helps.
where are a lot of difference between servlets and web services, but the main is:
in the web development servlets is the front end object and work in the web container, Web services can have different roles: as backend or as middle layer object.

Does web api have more advantage than socket communication?

Does web api have more advantage than socket communication when I am writing a software need calling server to function?
If we write a web api,do we can take advantage of http, http server, web app framework to do more thing with less work than doing the same function by socket ?
If my client call my server through internet, Do we have not any reason to not implement it as web api ?
I'd say that 'web API' is-kind-of a 'socket API'. While socket API may be basically anything running over sockets, web API is done using the HTTP protocol. That has a bit of limitation but usually the advantages are more important:
You reuse existing protocols and methods instead of re-inventing your own ones. That makes the work easier for you, and much easier for your users who do not have to implement everything from scratch;
You can use existing tools (and even a regular web browser) to debug your API. Well, with socket API you usually can use telnet but with more complex cases, a web browser or any HTTP querying tool is simpler to use;
You reuse HTTP ports 80 (and/or 443). That usually means it's less likely that any firewall will forbid your users to access the ports used by your service;
And after all, if you choose the right technologies, you can reuse them 'in' or even 'as' web pages. For example, you can use AJAX or similar technologies to catch data from your API in scripts on your web page.
Even better, if you just use XML for the API output, you can basically make it an API and a web page at the same time. You simply add a reference to an XSLT stylesheet to it, and whenever a web browser uses that API, it will use it to transform the raw XML into HTML.
Web services only output XML instead of HTML. The reasons why you should create a web service does not differs from the ones for creating a web site.
A web API can be called remotely.
A web API can be called in an independant manner. That means that you can allow you user (and you) to use an other interface that the one you build for the final customer.
You can program the API the way you want. The only requirment is to produce valid XML. So, yes you can use some framework, you are supposed to use a web server as the ones that output webpages.
If the client call your service throught Internet (SAAS), creating a web service allow you to give a new interface. Web services are required in order to use SOAP and to allow refreshing of webpages and also to give the datas to a heavy client.

What is web-service and how to develop it

I am looking for some good starting point for developing web-service.
I have one application which has C++ library support using which I can get all the details of the product.
I am supposed to write web service SDK for the same.
Any help.
Web services generally refer to a technique that allows code to be called via HTTP requests and responses. This is similar to a web page, except that what is returned from a web service is usually not HTML intended to be displayed in a browser - it is usually data of some kind.
"Web Service" is one of those terms that means whatever the person saying it means. Basically, its just a way to access data or functionality via http. There's a few standardized methods - REST, SOAP for web services, or you can just serve up XML, JSON, or other data from a plain old server side web app.
What you'd want to do is investigate what form this Web Server you are supposed to write needs to be in (SOAP, REST, something else), and then go from there.

What is a "web service" in plain English?

I've been reading about "web services" here on SO, on Wikipedia, Google, etc., and I don't quite understand what they are. What is the plain English definition/description?
If I make a simple website using PHP that just, say, prints a random integer to the page... is this a "web service"? If not, why not?
A simple definition: A web service is a function that can be accessed by other programs over the web (HTTP).
For example, when you create a website in PHP that outputs HTML, its target is the browser and by extension the human reading the page in the browser. A web service is not targeted at humans but rather at other programs.
So your PHP site that generates a random integer could be a web service if it outputs the integer in a format that may be consumed by another program. It might be in an XML format or another format, as long as other programs can understand the output.
The full definition is obviously more complex but you asked for plain English.
Simplified, non-technical explanation:
A web serivce allows a PROGRAM to talk to a web page, instead of using your browser to open a web page.
Example:
I can go to maps.google.com, and type in my home address, and see a map of where I live in my browser.
But what if you were writing a computer program where you wanted to take an address and show a pretty map, just like Google maps?
Well, you could write a whole new mapping program from scratch, OR you could call a web service that Google maps provides, send it the address, and it will return a graphical map of the location, which you can display in your program.
There is a lot more to it, as some of the other posts go into, but the upshot is that it allows your application to either retrieve information FROM, or submit information TO some resource. Some other examples:
You can use a web service to retrieve information about books at Amazon.com
You can use a similar web service to submit an order to Amazon.com
You could CREATE a web service to allow outside applications to find out about product information within your company
you could create a web service to allow outside applications to submit orders to your company.
Yes that is a simple web service.
Web services are really nothing more than a request/ response mechanism that allows a client to remotely access/ modify data. There are formal standards for web services (SOAP, SOA etc), but your simple page is a service too.
The main downside to printing it to a page is that your service would return HTML. Preferable data formats are JSON and XML, because most client frameworks (and server frameworks) are designed around using JSON and XML.
So if you modified your service to return:
<RANDOM>some random number</RANDOM>
rather than:
<HEAD>...</HEAD>
<BODY>some random number</BODY>
then it would be more useful to most clients
In over simplified terms a web service is something that provides data as a service over the http protocol. Granted that isn't alway the case....but it is close.
Standard Web Services use The SOAP protocol which defines the communication and structure of messages, and XML is the data format.
Web services are designed to allow applications built using different technologies to communicate with each other without issues.
Examples of web services are things like Weather.com providing weather information for that you can use on your site, or UPS providing a method to request shipping quotes or tracking of packages.
Edit
Changed wording in reference to SOAP, as it is not always SOAP as I mentioned, but wanted to make it more clear. The key is providing data as a service, not a UI element.
A web service differs from a web site in that a web service provides information consumable by software rather than humans. As a result, we are usually talking about exposed JSON, XML, or SOAP services.
Web services are a key component in "mashups". Mashups are when information from many websites is automatically aggregated into a new and useful service. For example, there are sites that aggregate Google Maps with information about police reports to give you a graphical representation of crime in your area. Another type of mashup would be to take real stock data provided by another site and combine it with a fake trading application to create a stock-market "game".
Web services are also used to provide news (see RSS), latest items added to a site, information on new products, podcasts, and other great features that make the modern web turn.
Hope this helps!
The best plain English explanation comes from using an analogy:
Web pages allow people to communicate and collaborate with each other.
Web services allow programs to communicate and collaborate with each other.
Your PHP example is a web service by that definition, because the output could be consumed by another program. But in reality, HTML screen-scraping is not a reliable or maintainable way of producing web services.
For most sites you have HTML pages that you visit when you use your browser. These are human-readable pages (once rendered in your browser) where a lot of data might be crammed together, because it makes sense for humans.
Now imagine that someone else want to use some of that data. They could download your page and start filtering out all the "noise" to get the data they wanted, but most websites are not built in a way where data is 100% certain to be placed in the same spot for all elements, so in addition to being cumbersome it also becomes unreliable.
Enter web services.
A web service is something that a website chooses to offer to those who wish to read, update and/or delete data from your website. You might call it a "backdoor" to your data. Instead of presenting the data as part of a webpage it is provided in a pre-determined way where some of the more popular are XML and JSON. There are several ways to communicate with a webservice, some use SOAP, others have REST'ful web services, etc.
What is common for all web services is that they are the machine-readable equivelant to the webpages the site otherwise offers. This means that others who wish to use the data can send a request to get certain data back that is easy to parse and use. Some sites may require you to provide a username/password in the request, for sensitive data, while other sites allow anyone to extract whatever data they might need.
A web service is a collection of open protocols and standards used for exchanging data between applications or systems. Software applications written in various programming languages and running on various platforms can use web services to exchange data over computer networks like the Internet in a manner similar to inter-process communication on a single computer. This interoperability (e.g., between Java and Python, or Windows and Linux applications) is due to the use of open standards (XML, SOAP, HTTP).
All the standard Web Services works using following components:
SOAP (Simple Object Access Protocol)
UDDI (Universal Description, Discovery and Integration)
WSDL (Web Services Description Language)
It works somewhat like this:
The client program bundles the account registration information into a SOAP message.
This SOAP message is sent to the Web Service as the body of an HTTP POST request.
The Web Service unpacks the SOAP request and converts it into a command that the application can understand.
The application processes the information as required and responds with a new unique account number for that customer.
Next, the Web Service packages up the response into another SOAP message, which it sends back to the client program in response to its HTTP request.
The client program unpacks the SOAP message to obtain the results of the account registration process.
Simple way to explain web service is ::
A web service is a method of communication between two electronic devices over the World Wide Web.
It can be called a process that a programmer uses to communicate with the server
To invoke this process programmer can use SOAP etc
Web services are built on top of open standards such as TCP/IP, HTTP
The advantage of a webservice is, say you develop one piece of code in .net and you wish to use JAVA to consume this code. You can
interact directly with the abstracted layer and are unaware of what
technology was used to develop the code.
Webservice is a technology by which two or more remote web applications interact with each other over network/internet. It can be implemented using Java, .net, PHP etc.
Features of Web service:-
Using web services two or more systems exchange data over network. Data are exchanged either using XML or JSON.
Any web service has two parts Server end where the service is deployed and the client part where the service is accessed by its clients. Any web service can have multiple clients. When a travel portal is selling tickets of an airliner. Portal is client and the Airline is the server as it is selling its service.
Web services can be synchronous or it can be asynchronous also.A web application can interact with many web services but these web services are loosely coupled with their client web applications. That means any change in the parent application has little or no effect on the web services or vice versa.
Web services can carry attachment document also like PDF, Word etc. with its XML payload. Java provides separate API for this type of web services.
A web service always hides the internal complexity of the service to its clients. For an example, an airliner which is selling tickets via a third party portal is only gathering end user info via a web service and in return it is providing ticket. The portal which is selling ticket doesn't have to bother about the internal complexity of the airlines ticket reservation systems.
A web service can be of fire and forget type or it can return something. Suppose, a web application just want to send some info to a third party application. The sender doesn't need any acknowledgement from the receiver. In this type of scenario we need a fire and forget type of web service.
A web service, as used by software developers, generally refers to an operation that is performed on a remote server and invoked using the XML/SOAP specification. As with all definitions, there are nuances to it, but that's the most common use of the term.
An operating system provides a GUI (and CLI) that you can interact with. It also provides an API that you can interact with programmatically.
Similarly, a website provides HTML pages that you can interact with and may also provide an API that offers the same information and operations programmatically. Or those services may only be available via an API with no associated user interface.
Well,
As #Vincent Ramdhanie has said that a web service is not meant to be seen / consumed by end user but another program. So technically logic in your program will be:
In case of acting as a normal program
user on website -> HTML/JS/JQuery etc -> give me a random number ->ur program
Now
ur program -> generate random number -> generate HTML and encapsulate o/p -> go back to user
but in case of web service the flow changes a little:
user -> my application -> XML/JSON/some other format -> give me a random number ->ur program
Now
ur program -> generate random number -> generate XML/JSON/some other format -> my application -> generate HTML and encapsulate o/p -> go back to user
Hope this helps :)
A simple definition would be an HTTP request that acts like a normal method call; i.e., it accepts parameters and returns a structured result, usually XML, that can be deserialized into an object(s).
Web services are almost like normal a web page. The difference is that they are formatted to make it very easy for a program to pull data from the page, to the point of probably not using any HTML. They generally also are more reliable as to the consistency of the format, may use a different formal process to define the content such soap or raw xml, and there is often also a descriptor document that formally defines the structure for the data.
A way of sending a message to invoke an operation on another computer. The difference between web services and previous methods is what gets sent over the wire is standardized at a higher level.
Old way: describe endians, encoding, port numbers, etc.
Web Service: URL, XML
Web Service is like a medium of commuication between two unrelated programs. The programs use a specified protocol(Usually Simple Object Access Protocol (SOAP)) as medium to understand what REQUEST/RESPONCE they are to process/execute on there respective end.
A web service defines a contract of actions that a server will perform for you. The format and protocol doesn't really matter, but you should have some set definition of how the communication happens.
In your example, it depends, if that is being used in another application that reads that number, yes it is service, otherwise, it's just a webpage with a number.
In simple words Web service could be any simple program ex: add two numbers which should be published over the UDDI and can be consumed by another program.WSDL will have the endpoint to locate the webservice and also the binding and port details.
'Web Service' is composed of two words,'Web' and 'Service'.
What is 'Web'? 'Web' means 'World Wide Web'.
'Service' for what? Not for Human,if so,it's 'Web Page',such as text,images,video etc.
It's for Programs to communicate through the Internet using the same technology the 'Web' used,such as TCP,HTTP etc.
'Service' also means it provides some functions,like the 'Service Layer' in CRUD.
There are mainly two types:
1. SOAP(Simple Object Access Protocol)
2. RESTful(Representational state transfer)
Without prejudice to other definitions I would say that a web service is software system that allows for inter-operable machine-to-machine / application-to-application interaction over a network. This generic definitions would also help consider REST architectures to be a web service as they provide similar functionality albeit being an architectural style unlike the SOAP which is a fully defined protocol.