What do I have here? API or Web Service - api

I have a project for Master's Degree: design and implementation of web services for an elearning platform.
Now, I know that there are two main architectures for web services: SOAP, and REST
Now, I wanted to use REST architecture, so normally I would have something called "RESTful web services", so I started development with Django and Django Rest Framework
Now, this is the part where I get confused, Is this an API or Web Services
If it is an API, then how can I develop RESTful Web Services?
If it is both, please explain more if you could.
I'm very confused about this, and each time I try to understand, I get more confused, Please can someone clarify this to me?

An application programming interface (API) allows you to interact with a component, system, or resource. It's a very broad concept. To understand it, the emphasis should be placed on the word interface:
In computing, an interface is a shared boundary across which two or more separate components of a computer system exchange information. The exchange can be between software, computer hardware, peripheral devices, humans, and combinations of these.
When you need something from a component or you want it to do something for you, you don't just go in it and do it yourself, you "ask it" for that something or for that action by interfacing with it. The interface of the component says what it can do for you or what you can invoke from the component.
In regards to web services, you have to understand that a web service is in fact an API, because it's an interface with some component (in this case whatever is behind the web service itself: it can be a database, an application, a system, etc).
Like I said, an API is a very broad term. When you say web service, you are adding some restrictions to that term. For example, a web service is invoked over the network. Not all APIs are like this. Some API's can be exposed as libraries, or frameworks that you call directly from your code as methods or functions. So all web services are APIs, but not all APIs are web services.
If you want to build a web service, you can implement it with REST or with SOAP. There is a difference between the two (REST is an architectural style, while SOAP is a protocol), but as concepts they work the same: they provide an interface with which to interact over the network, i.e. an API. But since you are using Django, thus Python, I suggest you go the REST way, not SOAP (support for SOAP in Python isn't all that great).

Related

What is the difference between an API and Microservice?

I create my API rest with Django, but I don't understand how convert an API to micro services, I don't understand the real difference between these.
I see an API like a micro service, but I don't know convert an entire API in micro service, I need create micro web servers?
Please, I can't understand a micro services, and I need understand this.
A microservice exposes it's interface, what it can do, by means of an API. The API is the list of all endpoints that a microservice respond when it receives a command/query. The microservice contains the API and other internal+hidden things that it uses to respond to client's requests.
An API is all that the clients see when they look at the microservice, although the microservice is bigger than that. A microservice hides its internal structure, it's technology stack, it's database type (sql, nosql - it could be anything); a microservice could move from sql to nosql, from python to php, but keep it's API unchanged.
API - It a way of exposing functionality over web. Imagine you have developed some functionality in .Net but not you are developing some software in a different language. Would you develop the same functionality again? No. So, just expose it via web service.Web services are not tied to any one operating system or programming language. For example, an application developed in Java can communicate with the one developed in C#, Android, etc., and vice versa.
Microservice - They are used to break a complex software into small pieces of individually deployable, testable, loosely coupled sub-modules. Micro Services are designed to cope with failure and breakdowns of large applications. Since multiple unique services are communicating together, it may happen that a particular service fails, but the overall larger applications remain unaffected by the failure of a single module.
API Vs Microservice - Now that we have broken our complex software into loosely couple sub-modules. These sub-modules communicate with each other via an API. Therefore, Microservices and an API solve different problems but works together!
More Details:
The Difference between Web Services and Micro Services
RESTful API vs Microservice
a microservice is an autonomous RESTful service. It means, there is just one service on each server. In Spring Boot when you bootstrap your RESTful service, it will get an instance of tomcat(it's embedded tomcat) and run your service on it. So, if you have more than one service on a server, it is not a microservice, because these services are not autonomous.

Understanding WCF from a layman's point of view

I am relatively new to WCF. I am developing Web application.
I am trying to understanding "Why WCF" and read many articles .
But in many places it has been mentioned "to developed service oriented architecture ,to asynchronously send data" without any detailed explanation / any basic example.
Can somebody please let me know one simple example in layman's term ,"Why WCF" so that I can appreciate its existence.
I have had conversations with many people but none of them were able to answer this basic question.
I am also aware that ,many hundreds of applications have gone live before WCF was there...
Suppose, you do have a task to make a procedure of recieving of the coordinate point (lat,lon) and and returning the picture of the surrounding area. Or to make a language translator from voise input to text output. These jobs could uses several servers with a lot of data and could makes some huge mathimatic calculations. But you procedure should me quick, platform independend, secured, protocol-independent, consumed by different technologies (Web, Mobile, Applications). And at the same time it should be easy to consume by the end users, which do know nothing about you. As the main aim of ASP to handle web requests and generate the html responses, so the aim of WCF is to supply the end user with some useful functionality, developed by another user, remotly.
The developer creates a service (WCF) where he specifies its adress, binding and contract. Knowing these parameters other developers can consume this service. They can consume it by ASP, SilverLight, WPF, WinForms or any other technology (even none-microsoft), using SOAP protocol.
From Wikipedia:
The Windows Communication Foundation (or WCF) is an application
programming interface (API) in the .NET Framework for building
connected, service-oriented applications.
WCF is meant for designing and deploying distributed applications
under service-oriented architecture (SOA) implementation. **
Architechture
** WCF is designed using service oriented architecture principles to support distributed computing where services have remote consumers.
Clients can consume multiple services; services can be consumed by
multiple clients. Services are loosely coupled to each other. Services
typically have a WSDL interface (Web Services Description Language)
that any WCF client can use to consume the service, regardless of
which platform the service is hosted on. WCF implements many advanced
Web services (WS) standards such as WS-Addressing,
WS-ReliableMessaging and WS-Security. With the release of .NET
Framework 4.0, WCF also provides RSS Syndication Services,
WS-Discovery, routing and better support for REST services. Endpoint A
WCF client connects to a WCF service via an Endpoint. Each service
exposes its contract via one or more endpoints. An endpoint has an
address (which is a URL specifying where the endpoint can be accessed)
and binding properties that specify how the data will be transferred.
http://en.wikipedia.org/wiki/Windows_Communication_Foundation
Useful resources:
http://msdn.microsoft.com/sv-se/library/dd943056%28en-us%29.aspx
http://www.wcftutorial.net/
http://blah.winsmarts.com/2008-4-Writing_the_WCF_Hello_World_App.aspx
http://blah.winsmarts.com/2008-4-Writing_your_first_WCF_client.aspx

WCF Pub Sub Service Location?

This question is to answer some confusion in direction I was given regarding where my WCF pub sub service should reside in relationship to a website that will be utilizing it. Basically, I'm developing a WCF Pub Sub service as an API to coincide with a SAAS solution. The site will actually utilize it's own API for the large majority of functionality. There is to me connectors installed on client local LANS for integration with local software systems to their networks, so these will also use the API (hence the pub sub, for real-time updates pushed down from the api)... I was told that I should have the WCF service reside in my site, meaning:
http://saassolution.com/api/wcfservice.svc ... the reasoning I was given, was that utilizing the service via javascript would become incredibly cumbersome if it wasn't a part of the project.
I would think the WCF service should reside at a location like so:
http://api.saasolution.com/wcfservice.svc
The ladder is how sites like twitter, and linkedin do this, so I'm confused at the direction I was given. Can anyone provide some insight as to the pros and cons of each approach... or if there is really a difference at all... or a recommendation?
Thank you.
The only assumption one could make for putting the wcf api within the site application could be the issue with cross domain xhr.

WCF Web Api vs WebHttpBinding

I'm new to WCF RESTFull services developpment and I'm looking for some usefull information and your experience feedback about using webHttpBinding compared to the new WCF Web API http://wcf.codeplex.com/.
What I'm looking for is to know about the shortcomings of webHttpBinding and therefore why to use the new Web api and especially what problems the new API resolves.
If you could point me to some blog posts comparing both of them or just talking about the problems when using webHttpBinding I would appreciate. Thank you in advance.
Main shortcomings I would say is that the webhttpbinding makes it difficult to handle HTTP specific concerns. It works great if all you are doing is passing an object over HTTP that is serialized into XML or JSON and which may be transported over different formats.
HTTP is much more than a simple transport protocol for XML and JSON, it is an application layer protocol with rich semantics. Web API is specifically targetting folks that want to build systems over HTTP that fully levergage HTTP's richness.
Web API embraces that HTTP Resources can have a multitude of representations based on the needs of different clients. One end of the spectrum could be a dumb browser that just talks to a service using a Form url encoded post and a GET, while the other end could be a more rich client that uses Atom/OData or a hypermedia based media type.
Web API embraces that there are other HTTP specific concerns like conneg, etags, etc which allow better leveraging intermediary web servers.
Web API is designed with more testability in mind, thus you can address working with HTTP messages or other concerns in a more testable manner.
Web API has a more simplified configuration story.
You can read more about the rationale here: http://blogs.msdn.com/b/endpoint/archive/2010/11/01/wcf-web-apis-http-your-way.aspx
The most significant difference for me is the change in programming model. You no longer write 'services' which expose 'operations' bound to HTTP idioms (GET, POST etc.). With Web APIs you create 'resources' (POCOs) with which your clients can interact.
Web APIs seem to be better at handling various custom media types (like PNG images for example).
Last but not least, Web APIs are far better suited for automated testing. For instance, you no longer have to use static context classes to access HTTP concepts such as response codes. You use POCO request and response classes which can be easily instantiated in automated tests using old-style new() operator.
I agree with Ladislav that Web APIs are just a preview now and building application on top of it can be both risky and forbidden by the means of license agreement (but I haven't checked that).
Have you considered #serialseb's OpenRasta? It is stable and offers very nice programming model for building RESTful services.
The Web API is something like possible future of REST development in WCF. It is just preview which can significantly change before final release (probably in next version of .NET framework). So if you want to build production REST service you should use webHttpBinding.
Available information about Web Api can be found for example on .NET Connected Framework team's blog and on the site you mentioned. It is simplification and extension of current REST API.
Web API provides a REST-friendly HTTP based API. Web API uses the patterns of MVC and is going to be very familiar to ASP.NET MVC developers. Web API can leverage the capabilities of HTTP as an application layer protocol, returning resources in multiple representations (XML, JSON, HTML etc.) according the the client's request headers.
On the other hand WCF webHttpBinding uses the patterns of WCF, and is going to appeal more to the WCF developer - ServiceContracts, OperationContracts, comprehensive (or overweight, depending how you look at it, config file), ability to self-host outside of IIS.
One of the things I like about Web API is the ability to use dynamic types to escape the constraints of the type system. I also like the default exception behavior in Web API - contrast WCF webHttpBinding where, by default, exceptions bubble up as HTTP 500 + an HTML payload (yuk!).
Its nice to have the choice between two excellent technologies here. I wouldn't describe Web API as 'newer' or 'better' that WCF, as this implies its a replacement technology and that WCF webHttpBinding is legacy, which I don't believe is true.
I chose to use WCF webHttpBinding recently to expose a JSON API for an existing WCF SOAP service. I believe it was a good choice because it fitted that style of that existing solution and minimized the amount of change required.

Confused about wcf despite my reading

I am learning wcf but I have trouble understanding the benefits. Is there ever a time I would want to use traditional web services?
I read another thread with these benefits:
Opt in model for members using a certain attribute
Better security
No need to worry about binding (can't understand how this is true)
No need to worry about the xml
I read Programming WCF Services however this was an advanced book a bit like CLR via C#. I am now reading Learning WCF Services and will read Essential WCF (is recommended).
What would happen if I use a normal class to try to talk to a web/service reference? I know this sounds really naive, it's just my lack of experience in web services.
I am coding some WCF services so I am getting exposed to the specifics. They are interacting with a SOAP web service provided by my web host so I can get stats on my site. Is there anything wrong in this approach?
Thanks
WCF is a unified programming model for developing connected systems. What this means is that you use a single framework to develop service-oriented solutions. WCF allows you to keep your service implementation relatively unaware and care free of what's going on under the covers as far as how your service is consumed by clients and communication is handled. This allows you to take your service implementation and expose it in various ways by configuring it differently without touching your service implementation. This is the unified part. Without WCF, you have to get familiar with a framework specific for a particular communication technology such as ASP.NET asmx web service, .NET remoting, MSMQ etc and usually those frameworks impose on your service implementation and creep in such as using WebMethod attribute or having to derive from MarshallByRefObject object etc and you just can not take your service implementation and easily expose it over another communication stack. If I have a service that adds two numbers, why can it not be exposed over http or tcp easily without having to worry about low level details? This is the question in your post regarding binding. Binding allows you take a service and configure it so that it can be exposed over different transports and protocols using different encodings without ever touching your service implementation.
Is there ever a time I would want to use traditional web service?
Web service uses well defined, accepted, and used standards such as HTTP and SOAP. So if you want your service to be consumed by wide range of clients, then you would want to expose your service as a web service. WCF comes with pre-configured bindings out of the box that allows your service to be exposed as a web service easily: basicHttpBinding and wsHttpBinding. You may also want to consider RESTful services which is an architectural style that fits more natural with the HTTP model. WCF supports RESTful services as well
What would happen if I use a normal
class to try to talk to a web/service
reference? I know this sounds really
naive, it's just my lack of experience
in web services.
WCF service can expose the wsdl for a service just like ASP.NET asmx web service does. You can generate a client side proxy by simply adding a service reference to your client project. There is also a command line tool called svcutil that also generates the client side code that allows you to easily communicate with the service. The client side service class basically mirrors the service interface. You create an instance of the client side proxy for the service and then simply call methods on it just like any other .NET object. Under the covers, your method call will get converted to a message and sent over the wire to the server. On the server side, that message will get dispatched to the appropriate service method.
I hope this helps a bit.There are lots of online content such as videos on MSDN and channel 9 that you check out. The more you pound on it and expose yourself to it, the clearer WCF will get I am sure. Also, WCF is THE framework Microsoft recommends to develop connected system in .NET. The other technologies ASP.NET asmx, WSE, and .NET Remoting will most likely still be available going forward but may not be supported and developed further.
There are a number of existing approaches to building distributed applications. These include Web services, .NET Remoting, Message Queuing and COM Services. Windows Communication Foundation unifies these into a single framework for building and consuming services.
Here is a link from MSDN Why Use Windows Communication Foundation?
WCF is really the "new" standard and new generation of web service - and even more generally, communications - protocols and libraries for the .NET world.
Whenever you feel the need to have two systems talk to one another - think WCF. Whether that'll be behind the corporate firewall in your company LAN, whether it's across the internet, by means of a direct call or a delayed message queueing system - WCF is your answer. Mehmet has written a really nice summary of how WCF is the unification of a great many communication standards that existed in the Microsoft world before WCF.
I would think with the "Learning WCF" book, you should be a lot better off than with Programming WCF - that's quite advanced stuff already!
One of the mainstays of WCF is the architecture that you always talk to your service through a proxy - whether that service runs on the same machine using NetNamedPipe binding or halfway around the world in Down Under on a server - no difference, you always go through a proxy. That then also allows WCF to be so extensible - thanks to the proxy always being between the client (your application) and the service, it offers excellent ways of extending the behavior and the inner workings of WCF to your liking and needs.
WCF basically builds on SOAP communications - so interfacing and using existing SOAP services should be no problem at all. With the WCF REST Starter Kit and in the upcoming .NET 4.0 release cycle, WCF will also extend its reach into the REST style web communications, if that's ever going to be a requirement of yours.
All this really shows one of the biggest strenghts of WCF: it's a unified and extremely flexible and extensible communication framework, that can handle just about anything you throw at it. That alone is more than enough reason to learn WCF (which can be dauting at first, I agree!), and you won't regret the effort you put into this endeavor.
Marc
Have you a specific application you are writing for, or just getting your feet wet?
Google protocol buffers, is a very good choice of communications. John Skeet & Marc Gravell have both done C# implementations. See here