- Details
- Written by: Stanko Milosev
- Category: REST
- Hits: 6595
Here is what I read from the RemObjects news group:
Note that REST isn't a standard, nor does it define any metadata format. The only thing REST specifies is that you use GET to retrieve data, POST to save it, PUT to insert it and DELETE to delete it. Besides that there's nothing that is specified at all.
---
Due to the lack of metadata or standardization for REST, this is a very complex subject.
--
Carlo Kok
We've been looking at a REST interface. As Carlo mentioned there is little in the way of standards and everyone seems ti implement their own. One of the simplest we've seen basically has the format
http://mysite.com/rest?method=MethodName&apikey=KeyValue&ArgName1=xyz&ArgName2=123
we've decided that the simplest way to implement this is through a standrad webbroker app which then links to a RO server.
The rest handling method, looks at the method name and calls this on the server, bit of a manual job at the moment but we are looking on at least creating an app to creat the code if you see what I mean.
The apikey is there to ensure that only valid users access the app.
--
Russell Weetch
- Details
- Written by: Stanko Milosev
- Category: REST
- Hits: 6229
Representational State Transfer
History
- REST is architectural style developed in parallel to the HTTP/1.1 protocol
- The largest known implementation of a system conforming to the REST architectural style is the Web
- It is possible to design a software system in accordance with Fielding's REST architectural style without using HTTP and without interacting with the World Wide Web
REST in short
- REST is more like style of programming
- Best example of REST is RSS
- REST is KISS
- Why Representational State Transfer?
- If user go to www.milosev.com
- he will get the web page (Representational)
- browser will change his page (State)
- if user click on a link he will change (Transfer) browser state
Concept
- Consists of clients and servers
- It doesn't use resources on a network or server
- example: web page, user can use web page, without sending messages to the server
- Client sends messaged to the server only when it goes to new state
Constraints
- Client - server
- clients are not concerned with data storage
- servers are not concerned with the user interface or user state
- Stateless
- each request from any client contains all of the information necessary to service the request, and any state is held in the client
- Cacheable
- well-managed caching partially and completely eliminates some client-server interactions, further improving scalability and performance
- Uniform interface
- simplifies and decouples the architecture
- principles:
- individual resources are identified in requests
- manipulation of resources through these representations
- self descriptive messages
- hypermedia as the engine of application state
- Layered system
- a client cannot ordinarily tell whether it is connected directly to the end server, or to an intermediary along the way
- Code on demand (optional)
- Servers are able to transfer logic to the client that it can execute (example: JavaScript)
Resources
- An important concept in REST is the existence of resources
- Client doesn't know is there cache, proxy, firewall, or anything else between client or server
- Client must know format of the information which is back
References
-
Wikipedia: http://en.wikipedia.org/wiki/Representational_State_Transfer
- Marco Cantu: http://blog.marcocantu.com/blog/soaprest.html
- xFront: http://www.xfront.com/REST-Web-Services.html
- Details
- Written by: Stanko Milosev
- Category: MS SQL
- Hits: 442
CREATE TABLE [dbo].[XmlModificationLanguageExample]( [ID] [uniqueidentifier] NOT NULL, [XmlField] [xml] NULL, CONSTRAINT [PK_XmlModificationLanguageExample] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]Final goal is to have XML like:
<root> <Parent Name="IamFather" Kind="Father"> <Value Name="Oldest" Type="Father" Value="True"/> <Value Name="Kids" Type="Children" Value=" <root> <Parent Name="IamTheSonOfMyFather" Kind="Father"> <Value Name="Oldest" Type="Father" Value="True"/> <Value Name="MyKids" Type="Geni.Files" Value=" <root> <Children Kind="Male" Count="12" ChildName="Stanko"> <Value Name="Name" Type="Male.Child" Value="48yrsOld"/> </Children> </root> " /> </Parent> </root> " /> </Parent> </root>First, lets insert XML like:
<root> <Parent Name="IamFather" Kind="Father"> <Value Name="Oldest" Type="Father" Value="True"/> <Value Name="Kids" Type="Children" Value="" /> </Parent> </root>
INSERT INTO [dbo].[XmlModificationLanguageExample] ([ID] ,[XmlField]) VALUES (NEWID() , '<root> <Parent Name="IamFather" Kind="Father"> <Value Name="Oldest" Type="Father" Value="True"/> <Value Name="Kids" Type="Children" Value="" /> </Parent> </root>')Now first I am gonna prepare XML which I will insert into the node:
<Value Name="Kids" Type="Children" Value="" />
DECLARE @FatherXML XML = '<root> <Parent Name="IamTheSonOfMyFather" Kind="Father"> <Value Name="Oldest" Type="Father" Value="True"/> <Value Name="MyKids" Type="Geni.Files" Value="" /> </Parent> </root>'; DECLARE @Kids nvarchar(max) = '<root> <Children Kind="Male" Count="12" ChildName="Stanko"> <Value Name="Name" Type="Male.Child" Value="48yrsOld"/> </Children> </root>'; SET @FatherXML.modify(' replace value of ( /root/Parent[@Name="IamTheSonOfMyFather"] /Value[@Name="MyKids"]/@Value)[1] with (sql:variable("@Kids") cast as xs:string?) '); select @FatherXML;Here notice that @Kids is of type nvarchar(max), where @FatherXML is of type XML Now that XML I will insert into main XML, and update the table in server:
DECLARE @FatherAsString NVARCHAR(MAX) = CONVERT(NVARCHAR(MAX), @FatherXML); UPDATE XmlModificationLanguageExample SET XmlField.modify(' replace value of ( /root/Parent[@Name="IamFather"] /Value[@Name="Kids"]/@Value)[1] with (sql:variable("@FatherAsString") cast as xs:string?) ') WHERE ID = '4D14CD89-002F-4985-B54E-CA2CC0DA6913'; select * from XmlModificationLanguageExampleHere notice that I am converting @FatherXML to NVARCHAR(MAX), and like this I updating attribute. Now, lets say that between nodes:
<Value Name="Oldest" Type="Father" Value="True"/> <Value Name="Kids" Type="Children" Value="" />I want to add new node:
<Value Name="Youngest" Type="Father" Value="True"/>after "Oldest":
UPDATE XmlModificationLanguageExample SET XmlField.modify(' insert sql:variable("@YoungestXML") after ( /root/Parent[@Name="IamFather"] /Value[@Name="Oldest"] )[1] ') WHERE ID = '4D14CD89-002F-4985-B54E-CA2CC0DA6913'; select * from XmlModificationLanguageExampleHere is the whole SQL query:
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[XmlModificationLanguageExample]') AND type in (N'U')) DROP TABLE [dbo].[XmlModificationLanguageExample] GO CREATE TABLE [dbo].[XmlModificationLanguageExample]( [ID] [uniqueidentifier] NOT NULL, [XmlField] [xml] NULL, CONSTRAINT [PK_XmlModificationLanguageExample] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO DECLARE @ID uniqueidentifier = NEWID(); INSERT INTO [dbo].[XmlModificationLanguageExample] ([ID] ,[XmlField]) VALUES (@ID , '<root> <Parent Name="IamFather" Kind="Father"> <Value Name="Oldest" Type="Father" Value="True"/> <Value Name="Kids" Type="Children" Value="" /> </Parent> </root>') DECLARE @FatherXML XML = '<root> <Parent Name="IamTheSonOfMyFather" Kind="Father"> <Value Name="Oldest" Type="Father" Value="True"/> <Value Name="MyKids" Type="Geni.Files" Value="" /> </Parent> </root>'; DECLARE @Kids nvarchar(max) = '<root> <Children Kind="Male" Count="12" ChildName="Stanko"> <Value Name="Name" Type="Male.Child" Value="48yrsOld"/> </Children> </root>'; SET @FatherXML.modify(' replace value of ( /root/Parent[@Name="IamTheSonOfMyFather"] /Value[@Name="MyKids"]/@Value)[1] with (sql:variable("@Kids") cast as xs:string?) '); SELECT @FatherXML AS FatherXmlData; DECLARE @FatherAsString NVARCHAR(MAX) = CONVERT(NVARCHAR(MAX), @FatherXML); UPDATE XmlModificationLanguageExample SET XmlField.modify(' replace value of ( /root/Parent[@Name="IamFather"] /Value[@Name="Kids"]/@Value)[1] with (sql:variable("@FatherAsString") cast as xs:string?) ') WHERE ID = @ID; select * from XmlModificationLanguageExample DECLARE @YoungestXML XML = '<Value Name="Youngest" Type="Father" Value="True"/>' UPDATE XmlModificationLanguageExample SET XmlField.modify(' insert sql:variable("@YoungestXML") after ( /root/Parent[@Name="IamFather"] /Value[@Name="Oldest"] )[1] ') WHERE ID = @ID; select * from XmlModificationLanguageExample
- Details
- Written by: Stanko Milosev
- Category: MS SQL
- Hits: 2042
<NamesTree> <TypeOfName Name="Test" Kind="TestNames"> <Value Name="FirstName" Type="nvarchar(50)" Value="John" /> <Value Name="LastName" Type="nvarchar(50)" Value="Doe" /> <Value Name="Type" Type="int" Value="1" /> </TypeOfName> <TypeOfName Name="Test" Kind="TestNames"> <Value Name="FirstName" Type="nvarchar(50)" Value="Jane" /> <Value Name="LastName" Type="nvarchar(50)" Value="Doe" /> <Value Name="Type" Type="int" Value="2" /> </TypeOfName> </NamesTree>This is how my table look like:
CREATE TABLE [dbo].[Test]( [FirstName] [nvarchar](50) NULL, [LastName] [nvarchar](50) NULL, [Type] [int] NULL ) ON [PRIMARY]First I am gonna seed my table:
insert into test values ('John', 'Doe', 1) insert into test values ('Jane', 'Doe', 2)This is how SQL looks like:
select 'Test' '@Name' , 'TestNames' '@Kind' , 'FirstName' [Value/@Name] , 'nvarchar(50)' 'Value/@Type' , FirstName 'Value/@Value' , null , 'LastName' [Value/@Name] , 'nvarchar(50)' 'Value/@Type' , LastName 'Value/@Value' , null , 'Type' [Value/@Name] , 'int' 'Value/@Type' , Type 'Value/@Value' , null from test for XML path('TypeOfName'), root('NamesTree')