I have a requirement in my project where I will have to built a webservice. This webservice will do the following things:
Accept XML format data
Return XML format data
The XML input data will have an element will have login information and another element data which needs processing.
Now I am looking for a design pattern where in I can make the webservice code look nice neat and clean. Because the webservice has to do plenty of things like.
First Parse the xml
Authenticate the request by checking username and password
Create objects from the data and then save the data to database
Prepare and xml which will be returned to the client.
So I have around 4 major steps which will definately make the code look ugly if I write whole thing in .asmx.cs file.
If anyone can suggest any design pattern to suit this so that the code is easy to maintain in near future.
As this module is to be integrated in my existing project hence there are some restrictions, like I cant use some 3rd party module or dll.
So I was looking for something like Single Responsibilty principle, Chain of Responsibility or Command or Decorator Patterns or anyother oop concept that fits.
I have searched but havent understood which way to start.
Thanks.
M.
I wouldn't write any of that from scratch. Use ServiceStack or MS MVC 4 for the webservice host. Rely upon them to do the conversion from XML to/from your objects. Both of those frameworks include authentication features. Start by reading their tutorials. It sounds to me like you have no experience with ORMs or micro ORMs or the various database options. I'd read a lot of tutorials on those as well.
Related
I've never really heard of HAL until I started working on a new project that is making use of it. From what I can tell, it's basically a way to easily follow links to traverse your way around a restful API's structure.
So if I understand this correctly, both tools are to make it easier to traverse around an API's documentation to see all the different means of communicating with said API. Essentially both of these are tools used for documentation purposes only?
REST APIs must be hypertext driven. It's not merely for documentation purposes, but for driving all interaction with the API. If you're not driving the interaction through links and clients are building URIs from templates in documentation, it's not RESTful. The authors of Django-REST-Framework themselves recognize the name is inadequate.
http://www.django-rest-framework.org/topics/rest-hypermedia-hateoas/
You should read the links provided in that document, specially this one:
http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven
With that in mind, your REST API has to use a data format where links are standardized so clients know how to parse them. This would constrain most APIs to use HTML or XML, but since JSON is such a popular data-exchange format, there are some efforts into designing conventions for adding hypermedia-awareness to any format, like HAL.
Django-REST-Framework supports hyperlinks in the HTML output, but -- AFAIK -- it has no support for hyperlinks in other formats. You can use HAL-JSON if you want, but you'll have to implement support for it.
I was looking for an RDF project for django and I cant find any active.
This seems to be a good one http://code.google.com/p/django-rdf, but the last commit was in 2008, (4 years ago). The group in google-groups seems to be abandoned. Last no-spam post was in 2008.
Therefore it has no support for new django versions.
Is there any library or some prebuilt open source app to easily expose rdf data?
Maybe is easy to solve, like writing a view and returning something using https://github.com/RDFLib/rdflib in one or two lines of code, but I can't figure it out how to do it...
The idea using RDFlib would be to take a django object or collection of objects and transform it to rdf in some way, maybe using an rdf parser.
I thought I could give html responses if the client request "accept:text/html", and RDF if the user requested the same page using a html accept header with rdf+xml or rdf+turtle (and it could exist an app that handles that for me)
From what little I've read of RDF you are probably going to have to do manual work to get meaningful RDF statements from Django models since it's not a simple data representation format like JSON, it is trying to encode semantic meaning.
That said, have a look at django-rdflib:
https://github.com/odeoncg/django-rdflib
There doesn't seem to be any documentation (and it seems to have been built for a specific app) but the author has posted here about a manage.py syncvb command that generates an RDF graph from existing Django models:
https://groups.google.com/d/msg/django-rdf/14WVK7t88PE/ktAKJo-aCfUJ
Not sure exactly what views django-rdflib provides, but if it can make an RDFlib graph for you then you can probably use the serialization plugins provided by RDFlib to output rdf+xml or whatever from your own view.
http://code.google.com/p/djubby/
SURF is useful as a RDF->object mapper (or RDFAlchemy)
injecting rdfa into your templates should work either (if you want to avoid triplestores)
you can also expose your database as a sparql endpoint using a tool such as http://d2rq.org/
I have been developing a Mac Desktop app with an iOS device counterpart.
Basically I want to upload event information (music gigs etc.) from the Desktop to an online database and be able to read (only) the information whilst mobile.
I've got both apps working, using Core Data (with a sqlite database - I was going to use XML but the iOS doesn't seem to let me do that), but I'm at a loss when it comes to the Web Services part.
I've been googling and checking docs involving sqlite, XML, JSON, NSXMLParser (do I need restful services?)and umpteen other things and I'm just getting nowhere fast.
Could someone explain to me the principle involved? Do I actually need Core Data? Do I have to convert the sqlite data to XML and back again to read it via an iOS mobile device?
I feel I'm making this out to be way more complicated than it should be - or is it?
Hoping someone can put me straight. Hope I've given enough information.
What i do, and I have done many web service iOS apps. I make a webpage in JSON, call it, and then I use SBJsonParser, which parses the JSON into native objects, like a dictionary or array of dictionaries, then I display the data. It really is very simple.
The at a specific time like ViewDidLoad, I fetch the JSON file. Remember, the json document can be web service or just a text file. Whatever you need. JSON doesn't need extra code, is extremely lightweight, and parses without any interference into native objects. Less work for you.
We are considering to develop a Flash front-end to a web application written using Django. The Flash front-end will send a simple "id" to the server and in response receive a couple of objects. The application will be open only to authenticated users.
To the extend of my current knowledge (which is basic for Flash) we can either use AMF or take an XML or JSON approach. AMF seems to have an upperhand as there are examples out on the internet showing it can cooperate easily with Django's authentication mechanism (most examples feature pyAMF). On the other hand, implementing a XML/JSON based solution may be easier and hassle free.
Guidance will be much appreciated.
We've used pyAMF + Django on many projects here, and it's a breeze to setup and get running. If you need speed, AMF3 is probably your best bet. It's the smallest/fastest way to transfer data, and serialization is taken care of for you.
On the flip side, setting up json with Django isn't much work either, and it would give you the ability to hook other, non-AMF systems into it without any extra work. You just sacrifice a little speed for that benefit.
If you think you'll ever need other systems working with the backend, or if you think you might switch to an HTML-only, or offer some kind of non-Flash version of your app, I'd go JSON, otherwise, I'd use AMF.
first of all, you should design your app in such a way this doesn't matter. the transport layer should be completely encapsulated, leaving the encoding format transparent to the rest of the app.
personally I prefer JSON to AMF because it's human readable (which makes debugging easier) and there are implementations for every platform/language (so you can reuse the server part with JavaScript for example). And I prefer JSON to XML because it's more compact and semantically less unambiguous as well as closer to common object models. Also it can transport numerical and boolean data in a typesafe manner.
JSON will probaby have the least complications and there's a great google code project that has JSON encoders and decoders here: http://code.google.com/p/as3corelib/
I need to document an application that serves as a facade for a set of webservices. The application accepts SOAP requests and transforms these requests into a format understandable by the underlying web service. There are several such services, each with its own interface. Some accept SOAP, some HTTP POST, some... other formats not mentioned in polite society.
I need to document how we map the fields from our SOAP calls to the fields for these other formats. Before everyone cries "XSLT" I must mention that the notation must be human-friendly. Ideally it would be something Excel-able.
Has anyone encountered this sort of problems before? How did you solve it? Is there a human-friendly notation for tree-to-tree transformations that can fit on a spreadsheet?
I've had to do just this. The way I did it was to just start writing, following the hierarchical structure.
I eventually would find that I was repeating myself. An example was that certain elements had a common set of attributes. I would pull the documentation of that common set up before the sections on the specific elements. Same thing with documentation of handling of specific simpleTypes.
Eventually, there was even some high level discussion on the overall flow and "philosophy" of the transformation. But I let it all happen bit by bit, fixing it as I became bored with repetition.
That said, I'm a developer, not a tech writer.
I haven't really found anything so far, but I've found pointers to many libraries that help transform objects of one type to another in Java. For reference, I'm listing the most promising ones here, all doing some kind of JavaBean to JavaBean conversion:
Transmorph
EZMorph
Dozer