I actually want to ask that what is the way to create an API for sites such as Facebook.. Twitter etc. I am an IT Graduate and do know programming but still wonder that how do people start to create their own set of API's for such websites. And Everyday people have a new API to access the site. Can someone throw light on the standard process that is being followed so as to achieve this ?
I think there is no unique canonical way for the design of a public web API. You could find best practices through.
This will also depend of the complexity of what you want to expose.
Basically you'll want it to operate over standard HTTP and be accessible both by backend systems and by browser client. So you'll choose either XML or JSON as the dataformat as it is supported by everybody.
A common pratice would be to adhere to the REST architecture, but this is only one choice over many. Today REST is a buzz word. So many tend to use it even if not really suited to their needs.
Like any public API, you should take great care of backward compatibility and futureproof design. The whole refactoring thing can be thrown away as you can't break client code when developping new features. A classical way to deal with this is to publish API per version and let the client stick with the version it support.
Check Spring Social. It is a framework to write api to connect to social networking websites. Also for doing that you need to have knowledge of OAuth protocol which is one of the protocols used to allow access to private information with other websites.
Related
sorry if my english isn't perfect.
I'm trying to make an app and I need to exchange information between more devices.
I thought that could be a solution connect the devices on a server but I really don't have the idea where start.
What language I need to study to make this? There is a better solution?
This highly depends on what you are trying to achieve in the first place. It would be helpful if you could tell what you are trying to do, but I will still outline some general aspects:
You need to decide, what information is going to be exchanged and how this should happen
What information: Figure out, what exactly needs to be sent and received. Generic text messages? Images? Byte Streams?
How should this be done: Generally spoken, there are two approaches of getting information as a client: Polling and subscribing.
Polling: This approach means to periodically check an endpoint for new data. For example, HTTP uses this way: A web browser or any other client (REST-Client for example) periodically requests information from a HTTP-Server, using a connection just for this single request.
Subscribing / Sync / Notification: In some way or another, the client tells the server that it is interested in the information and wants to get notified when there is something new. The connection is initiated at the beginning and held open for further usage. The benefit of this approach is that changes are received immediately, but on the other hand a permanent connection needs to be maintained.
Things to study
At the beginning, get a good understanding of the TCP/IP Protocol, how Sockets work, how common Protocols do their job (e.g. HTTP, WebSockets)
Take a look at specific Protocols working on top of the basic ones
Tip: REST: Most common WebServices Protocol, providing a common way to exchange stateless data. Uses Polling.
WebSockets: Socket connection using Web Browsers. Commonly used to update information without needing to poll.
There is no specific language to learn for connections. It's more about understanding what the difficulties are and what ways have been invented to address this. Once you get to this point and know what you want to do, it's possible in every language.
Recommendation: As you seem to use Java/Android, I would try to use REST. A really great client-side library for REST on Android is Retrofit. For the server side use what fits for you .. common Java way would be to use Jersey, but you are free to choose from a lot of choices. If using Jersey is too hard for the beginning, maybe take a look at the JS/NodeJS world, those guys invented Express, which allows you to create a REST service out of just a database, wihtout having to code a lot.
First you need to decide if you want to go for an Android or an iOS application. There are other various mobile operating systems as well, but these are widely used . If you want to go for android which is most widely used in my opinion, then you need to learn Java. If you want to go for iOS application, then you need to learn swift or objectiveC. These languages provide the API to connect with various types of services such as Facebook, Firebase and Amazon etc. If you want to connect to some other local server who’s IP is known to you, then you can use socket programming to send messages.
There could be many ways you can implement this. One way will be using Web services. Of course REST might be a better option, if you follow this approach. You can implement Your service(server side code) with any language. I will recommend you use java since you are already using android.
Aside from this You might need to go through the basics of REST, its specifications and
some reference implementations for language of your preference.
I am working on an application which is built in .NET and Java. The Java component contains the complete Rule base using Redhat BRMS suite. The .NET client (UI and desktop based applications) will be consulting the Java Rule engine and sending/receiving the JSON data. The decision which has been taken is to expose the Rules engine (Redhat BRMS 6.0.0 using Drools) as a REST based API. I have come-up with the following design approaches:
Write a REST controller in Spring framework and service classes for calling BRMS.
Write a simple REST controller using JBOSS proprietary RESTSY or JAXRS.
Write a Camel adapter and wrap the REST calls behind the Camel and let the Camel talk to Drools.
Wrap REST behind SOAP based webservices.
I want to ask which one would be the better approach for designing such as System.
Any other thoughts are welcome.
As might be obvious from https://github.com/gratiartis/sctrcd-payment-validation-web and https://github.com/gratiartis/qzr my general preference is for exposing my Drools business rules using REST APIs in a Spring application.
The only alternative I consider in the above list is 4, where the API is exposed through a SOAP web service. Albeit definitely not wrapping a JSON REST service! A well-designed Spring application can expose functionality through both REST and SOAP APIs with very little effort.
I have usually exposed via SOAP when working with .NET clients. Firstly, the .NET tooling has excellent support for generating proxies based on WSDL that you have defined. Secondly, the WSDL forms a well-defined contract which both you and the client developers must obey. Having a strict contract can be very useful in preventing arguments. Although if your interface is simple, it may not be so much of a benefit.
The other key reason is that the WSDL does not change unless you change it deliberately. A REST JSON API may seem quick to develop, thanks to Jackson generating everything for you. However, it can expose your internal object model (and dependencies!), meaning that unless you are careful, what seems like a trivial change to an internal model can make private data visible and can break clients.
All that said, if you can keep the API reasonably simple and have a good relationship with the .NET devs (perhaps you're one of them), then going with the Spring REST API would be my recommendation. Feel free to steal code from the github repos if it can help you get started!
btw - If you were to consider Camel, it's worth noting that there is a Drools-Camel component which does quite a bit of the work for you.
In my view,
I would go with the option 1. This is the simplest and easiest approach.
Option 2 may be second choice.
Option 3 - Looks like if there are some routing rules you could choose. Again its could make it complex.
And definitely not option 4 to make it complicated with SOAP.
I'm working on a java problem that (at least is trying) to utilize the twitter API, however, it is my first project using any type of API and I am a little confused. What is the benefit of using a java library for the twitter API such as Twitter4J and how would one go about not using one? I'm a little fuzzy on the topic of APIs in general and I'm not finding anything in my searches that really makes it clear how to use one.Do I need to use a Java library or can I do it without one? what are the pros and cons of using one vs not using one. I am relatively new to this and am having some issues. Any help?
First what an API is:
An application programming interface (API) is a particular set of
rules ('code') and specifications that software programs can follow to
communicate with each other. It serves as an interface between
different software programs and facilitates their interaction, similar
to the way the user interface facilitates interaction between humans
and computers. An API can be created for applications, libraries,
operating systems, etc., as a way of defining their "vocabularies" and
resources request conventions (e.g. function-calling conventions). It
may include specifications for routines, data structures, object
classes, and protocols used to communicate between the consumer
program and the implementer program of the API
The use of the Twitter4J API would allow you to easily call commands that do complex operations, such as get tweets as they are coming in. For projects such as this, using an API is best way to go about it as you are also going to be required to get an access key which allows you permission to use the API.
Examples using Twitter4J: http://twitter4j.org/en/code-examples.html
You need to distinguish between an "API" and a "Library"
You NEED the Twitter API: it's the thing that connects twitter to your code. You can use this to send a "post this to my account" command for instance.
You CAN use a library: it helps your code talk to the api, by doing some of the work for you. You can call a function with only a string as parameter, and this function calls the forementioned send-to-twitter API
You can ofcourse say things like that the library has an API, but this would be confusing the situation a bit.
In the end it is quite nice to use the library because it helps you by writing code in your language.
we are looking to create a web service to provide functionality for stateless data transactions on a single data store. the service will be consumed by applications running several potential environments - at least windows .net, php, and java, but possibly more.
what is the best format to use for passing data back and forth? "best" i would consider to be the format in the sweet spot between ease of consumption and strongly typed content. at one end, SOAP tells you everything you need to know about the service but requires a good deal of processing on the client side to parse. On the other side would be JSON for its minimalist format and ease in parsing, but obviously the client needs to have a very good idea about what data it should be expecting.
would one of these solutions be more ideal than the other? is there another format to consider?
as a follow up, what frameworks can you recommend to implement the format on the server side? our server OS is linux, so php or java would be the preferred solution, but an alternate platform like node.js could also be considered. something like WCF in the .NET world would be ideal since you can write the business logic once and let the presentation framework make it available in several formats simultaneously.
As #WhiteFang34 recommended, REST is a very accessible protocol to you. Even though it is not a standard, it is widely used and well documented in most modern programming languages.
REST merely defines what each HTTP method should do, but you still need to decide what format to use. JSON and XML are the most popular ones, but from my experience JSON is a lot less troublesome to work with in most cases.
If you use the WCF REST 4.0 template you can get a REST and SOAP endpoint on the same service. Its easy as pie. I think that RESTful is the best way to go for most things.
The nice thing about REST is that its easy to consume. It can be a bit more work to consume, but it works very cleanly. SOAP is harder to consume, but once you get it wired up most frameworks work great with it. Myself, I have never had much luck with using SOAP services across many platforms.
You should consider using REST. It's popular for web services. I recommend reading A Brief Introduction to REST that goes over application-to-application communication with REST. There's also RESTful Web services: The basics. There are plenty of REST solutions to choose for with Java:
Apache CXF
Jersey
RESTEasy
Restlet
Spring (docs)
There's also the JAX-RS API that most of them adhere to (all of these except Spring).
Is there a Java library that provides functionality for developing social network applications such as add friend, find nearest neighbors, send message etc. I know this is too much to ask for but just wanted to know if such library really exists or not.
This is very broad functionality. Here are some related projects:
OpenSocial Java client - it implements the OpenSocial protocol
Spring-social allows integration with popular social networks
Apache Shindig an open-social based platform.
If you want to add support for existing social network applications than I think all of the Bozho's solution would be ok for socializing your applications. For distance based calculations (geocoding) you will have to use separate mechanism and librabry google and yahoo both have an excellent api for that though these differ in terms of their usage restrictions so its good to you research before deciding one, Yahoo also supplies a promising feature YQL which is also useful in some cases.... Which one of them is better depends on your requirements... see following questions finding latitude and longitude, another similar question and finding distance between two zipCodes
If you want to create your own social networking site as then I think you will have to start by ur own... However It would be a nice idea to integrate that site with existing popular social networks using OAuth or open ID....
#Bozho's answer is valid, all those libraries integrate with a set of Social services.
This question really depends on the extent of integration you want. I've worked on a couple of large scale Social aggregators and I've found that such a silver bullet just doesn't exist. I've found the best results in my experience by using small lightweight libraries that do one thing well.
For example, say I wanted to integrate with Twitter, Facebook, and Google Talk. I might use Scribe for my authentication code, Jackson for parsing JSON API responses to my business objects and Smack for doing my XMPP work.
There are certainly pros and cons for both methods; the major benefits I've found of avoiding massive libraries are:
Flexibility. For example your business objects only contain the information you care about.
Testability. You can compose your components in such a way that tests are easy to write around them.
Robust. You are not constrained by a 3rd parties implementation of typically volatile 3rd party APIs.
Less code. Using a collection of small, proven libraries will result in less of a footprint: less code to manage = less that can go wrong.