{"id":1083,"date":"2009-04-20T15:23:00","date_gmt":"2009-04-20T15:23:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/cesardelatorre\/2009\/04\/20\/using-murl-a-textual-oslo-dsl-for-restful-clients\/"},"modified":"2009-04-20T15:23:00","modified_gmt":"2009-04-20T15:23:00","slug":"using-murl-a-textual-oslo-dsl-for-restful-clients","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/using-murl-a-textual-oslo-dsl-for-restful-clients\/","title":{"rendered":"Using \u201cMUrl\u201d \u2013 A textual Oslo DSL for RESTful Clients"},"content":{"rendered":"<p><TABLE border=\"0\" cellSpacing=\"0\" cellPadding=\"2\" width=\"400\">\n<TBODY>\n<TR>\n<TD vAlign=\"top\" width=\"123\"><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/image_6.png\"><STRONG><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/image_6.png\"><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/image_thumb_2.png\" width=\"108\" height=\"59\"><\/A><\/STRONG><\/A><STRONG> <\/STRONG><\/TD>\n<TD vAlign=\"top\" width=\"277\"><STRONG>\u201cMUrl\u201d is a textual DSL and runtime for interacting with REST\/HTTP services.<\/STRONG><\/TD><\/TR><\/TBODY><\/TABLE>\n<H3>It is actually just a great Oslo-DSL sample, as you can download it (all its source code) from MSDN.com:<\/H3>\n<P><A href=\"http:\/\/download.microsoft.com\/download\/4\/0\/B\/40B632EC-F201-43EE-8E29-C398A9DA8468\/MUrlSample.msi\">http:\/\/download.microsoft.com\/download\/4\/0\/B\/40B632EC-F201-43EE-8E29-C398A9DA8468\/MUrlSample.msi<\/A><\/P>\n<P>As long as I know, \u201cMUrl\u201d has been mainly developed by <STRONG>Douglas Purdy<\/STRONG>. I saw his session at MIX09, which was fabulous; so now, I want to explain what \u201cMUrl\u201d is and how to use it. This post is, in fact, explaining most of the content that Doug told in MIX09.<\/P>\n<P>So, Just like we already have within <STRONG>Oslo<\/STRONG> and <STRONG>\u201cM\u201d Language<\/STRONG>, the following <STRONG>DSLs<\/STRONG>, at different levels: <\/P>\n<P>&#8211; <B>MGraph<\/B><\/P>\n<P>&#8211; <B>MSchema<\/B> (for SQL)<\/P>\n<P>&#8211; <B>MGrammar<\/B> (to create custom DSLs)<\/P>\n<P>We will have many more Oslo DSLs, (many of them, initially as examples), like:<\/P>\n<P>&#8211; <B>MUrl<\/B> (DSL for consuming Services, <U>this is the one I\u2019m going to write about<\/U>)<\/P>\n<P>&#8211; <B>MService<\/B> (DSL for building Services, based on WCF-REST, not released, yet)<\/P>\n<P>&#8211; <B>MWeb<\/B> (DSL for building Webs, based on ASP.NET, not released, yet)<\/P>\n<P>&#8211; <B>MEntity<\/B> (DSL for building Entity Framework graphs, etc., not released, yet)<\/P>\n<P>&#8211; Your great \u201cMCustomSmartDSL\u201d\u2026 \ud83d\ude09<\/P>\n<P>Ok, so <B>&#8220;MUrl&#8221;<\/B> is an &#8220;M&#8221; based domain specific language (DSL) that provides a very compact and intuitive mechanism to communicate with RESTful services. You can use it from INTELLIPAD (for testing) or you can even use its run time from a .NET program (I\u2019ll show both in this post). <\/P>\n<H4>Using \u201cMUrl\u201d from INTELLIPAD.<\/H4>\n<P>Steps:<\/P>\n<P>1.- First of all, install download from the URL I wrote up above, and install it. Or course, you need to have Oslo SDK already installed, as pre-requisite.<\/P>\n<P>2.- Start INTELLIPAD and select \u201cMURL Mode\u201d like I show below:<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image002_2.jpg\"><IMG title=\"clip_image002\" border=\"0\" alt=\"clip_image002\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image002_thumb.jpg\" width=\"659\" height=\"381\"><\/A><\/P>\n<P>3.- Then we can just start writing and executing HTTP requests!. Type:<\/P>\n<P><A href=\"http:\/\/live.com\/\">http:\/\/live.com<\/A><\/P>\n<P>Select that text line, and press Ctrl+Enter to execute that request. You\u2019ll see the results in a pane on the right:<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image004_2.jpg\"><IMG title=\"clip_image004\" border=\"0\" alt=\"clip_image004\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image004_thumb.jpg\" width=\"669\" height=\"328\"><\/A><\/P>\n<P>We can check that the HTTP status is OK, so we get the info. All right, It works!.<\/P>\n<P>4.- Even better, now we\u2019re going to consume RESTFul Web Services, like the TWITTER service.<\/P>\n<P>I login into TWITTER, just to show what messages I have:<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image006_2.jpg\"><IMG title=\"clip_image006\" border=\"0\" alt=\"clip_image006\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image006_thumb.jpg\" width=\"675\" height=\"373\"><\/A><\/P>\n<P>Right, so last message is the one that says: \u201cYes! OSLO and MUrl rocks!!\u201d.<\/P>\n<P>We can query info from TWITTER, like executing the following GET request:<\/P>\n<P>GET <A href=\"https:\/\/twitter.com\/statuses\/public_timeline.xml\">https:\/\/twitter.com\/statuses\/public_timeline.xml<\/A><\/P>\n<P>We get the HTTP results. Nice, nothing new, similar than before, but now we\u2019re quering a REST Web Service:<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image008_2.jpg\"><IMG title=\"clip_image008\" border=\"0\" alt=\"clip_image008\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image008_thumb.jpg\" width=\"686\" height=\"291\"><\/A><\/P>\n<P>5.- In this step we\u2019re going to submit a message to TWITTER service using MUrl. Now, type the following text into INTELLIPAD: \n<TABLE border=\"1\" cellSpacing=\"0\" cellPadding=\"0\">\n<TBODY>\n<TR>\n<TD vAlign=\"top\" width=\"569\">\n<P>POST https:\/\/twitter.com\/statuses\/update.xml<\/P>\n<P>with [&lt;status&gt;Este lo voy a borrar desde MUrl&#8230;.&lt;\/status&gt;]<\/P>\n<P>as text\/xml<\/P><\/TD><\/TR><\/TBODY><\/TABLE><\/P>\n<P>If you just execute that POST, you\u2019ll get a 401 Http error, because in order to submit content to TWITTER, you must be authenticated, and we\u2019re not, yet:<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image010_2.jpg\"><IMG title=\"clip_image010\" border=\"0\" alt=\"clip_image010\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image010_thumb.jpg\" width=\"695\" height=\"298\"><\/A><\/P>\n<P>We\u2019re going to use WINDOWS CREDENTIALS MANAGER to create custom credentials for TWITTER. We\u2019ll use it later on from MUrl.<\/P>\n<P>Enter into Control Panel\\User Accounts and Family Safety\\Credential Manager:<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image012_2.jpg\"><IMG title=\"clip_image012\" border=\"0\" alt=\"clip_image012\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image012_thumb.jpg\" width=\"702\" height=\"469\"><\/A><\/P>\n<P>As you can see, I have created a \u2018Generic Credential\u2019 called \u201cTwitter\u201d. You can do the same clicking on the \u201cAdd a generic credential\u201d link.<\/P>\n<P>It is simple; it is composed by a Credential-Name, User Name and a Password:<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image014_2.jpg\"><IMG title=\"clip_image014\" border=\"0\" alt=\"clip_image014\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image014_thumb.jpg\" width=\"706\" height=\"270\"><\/A><\/P>\n<P>Remember the credential\u2019s name, as that name we\u2019re going to use it from MUrl, ok?. (In my case, I just called it \u201cTwitter\u201d).<\/P>\n<P>Then, add the following text to the original MUrl text request we wrote: \n<TABLE border=\"1\" cellSpacing=\"0\" cellPadding=\"0\">\n<TBODY>\n<TR>\n<TD vAlign=\"top\" width=\"576\">\n<P>\u201cauthenticate using [Twitter]\u201d<\/P><\/TD><\/TR><\/TBODY><\/TABLE><\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image016_2.jpg\"><IMG title=\"clip_image016\" border=\"0\" alt=\"clip_image016\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image016_thumb.jpg\" width=\"707\" height=\"303\"><\/A><\/P>\n<P>And now\u2026, It works!! :-). You can check it down below at my TWITTER web page:<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image018_2.jpg\"><IMG title=\"clip_image018\" border=\"0\" alt=\"clip_image018\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image018_thumb.jpg\" width=\"627\" height=\"336\"><\/A><\/P>\n<P>BTW, I had to change MUrl internal code in order to run it using Authentication.<\/P>\n<P>If you get the <STRONG>&#8220;Expectation Failed&#8221; error message<\/STRONG>, you have to fix it, as well. Take a look to this post:<\/P>\n<P class=\"MsoNormal\"><SPAN><FONT face=\"Calibri\">See: <\/FONT><\/SPAN><A href=\"http:\/\/www.biztalkgurus.com\/blogs\/biztalksyn\/archive\/2009\/04\/05\/issue-with-the-first-release-of-murl-sample-and-twitter.aspx\"><SPAN><FONT face=\"Calibri\">http:\/\/www.biztalkgurus.com\/blogs\/biztalksyn\/archive\/2009\/04\/05\/issue-with-the-first-release-of-murl-sample-and-twitter.aspx<\/FONT><\/SPAN><\/A><SPAN><\/SPAN><\/P>\n<P>So, there you have it!, you can use MUrl directly from INTELLIPAD.<\/P>\n<P>&nbsp;<\/P>\n<H4>Using \u201cMUrl\u201d from a .NET app.<\/H4>\n<P>Steps:<\/P>\n<P>1.- Now we\u2019re going to develop a .NET program which consumes MUrl DSL RUNTIME. It is a nice way to shrink .NET code\u2026<\/P>\n<P>In this case, I have a WPF app which is kind of a TWITTER message editor\/submitter:<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image020_2.jpg\"><IMG title=\"clip_image020\" border=\"0\" alt=\"clip_image020\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image020_thumb.jpg\" width=\"774\" height=\"486\"><\/A><\/P>\n<P>Take into account that I added two references to:<\/P>\n<P>&#8211; MUrlLib<\/P>\n<P>&#8211; System.DataFlow<\/P>\n<P>Then, I wrote the following .NET code to be executed when the button \u2018Upload Message to Twitter\u2019 is pressed:<\/P>\n<P>.NET CODE:<\/P>\n<P>\n<TABLE border=\"1\" cellSpacing=\"0\" cellPadding=\"0\">\n<TBODY>\n<TR>\n<TD vAlign=\"top\" width=\"569\">\n<P>var runtime = new Microsoft.Languages.MUrl.MUrlRuntime();<\/P>\n<P>string twitterCommand = @&#8221;POST https:\/\/twitter.com\/statuses\/update.xml with [&lt;status&gt;&#8221;<\/P>\n<P>+ txtTwitterMessage.Text + &#8220;&lt;\/status&gt;] &#8220;<\/P>\n<P>+ &#8220;as text\/xml &#8220;<\/P>\n<P>+ &#8220;authenticate using [Twitter]&#8221;;<\/P>\n<P>var statements = runtime.Parse(twitterCommand);<\/P>\n<P>var result = runtime.Execute(statements.ElementAt(0));<\/P>\n<P>MessageBox.Show(result.AsXml().ToString());<\/P><\/TD><\/TR><\/TBODY><\/TABLE><\/P>\n<P>You can see that we\u2019re constructing the same kind of simple MUrl text but within our .NET code\u2026 And, it just works in the same way!.<\/P>\n<H4>Looking into MUrl DSL M-Grammar program.<\/H4>\n<P>Cool!. So up to now, we\u2019ve been just using this cool textual Oslo DSL. But because of it is just a sample, we can take a look at how it is implemented.<\/P>\n<P>1.- Start INTELLIPAD and open the file \u201c<STRONG>murl.mg<\/STRONG>\u201d which you can find as part of the downloaded MUrl stuff. You\u2019ll see something like this:<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image022_2.jpg\"><IMG title=\"clip_image022\" border=\"0\" alt=\"clip_image022\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image022_thumb.jpg\" width=\"730\" height=\"424\"><\/A><\/P>\n<P>I want to highlight that now we\u2019re running on MGrammar Mode, just like the custom DSL sample I wrote in this blog-post:<\/P>\n<P><B>Creating a simple Textual DSL with Oslo, \u201cM\u201d Language, MGrammar and Intellipad<\/B><B><\/B><\/P>\n<P><A href=\"http:\/\/blogs.msdn.com\/cesardelatorre\/archive\/2009\/04\/20\/creating-a-simple-textual-dsl-with-oslo-m-language-mgrammar-and-intellipad.aspx\">http:\/\/blogs.msdn.com\/cesardelatorre\/archive\/2009\/04\/20\/creating-a-simple-textual-dsl-with-oslo-m-language-mgrammar-and-intellipad.aspx<\/A><\/P>\n<P>But in this case, it is a bit more complicated, of course.<\/P>\n<P>2.- Change to MGrammar-Mode&#8211;&gt; Tree Preview<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image024_2.jpg\"><IMG title=\"clip_image024\" border=\"0\" alt=\"clip_image024\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image024_thumb.jpg\" width=\"733\" height=\"186\"><\/A><\/P>\n<P>It will ask you for an INPUT FILE, so\u2026, just provide the MUrl Text we were writing!! (I called \u201cMUrl Demo Sentences.murl\u201d).<\/P>\n<P>Then, you can see how MUrl M-Grammar program is translating MUrl text to HTTP requests data (which will be used be MUrl runtime):<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image026_2.jpg\"><IMG title=\"clip_image026\" border=\"0\" alt=\"clip_image026\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image026_thumb.jpg\" width=\"730\" height=\"316\"><\/A><\/P>\n<P>We can even change the MUrl syntax from within the \u201cmurl.mg\u201d file, so for instance, we can now say that in order to do a GET, you can type DAME (in Spanish) or OBTAIN, as well. And it will work just the same! \ud83d\ude09<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image028_2.jpg\"><IMG title=\"clip_image028\" border=\"0\" alt=\"clip_image028\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image028_thumb.jpg\" width=\"908\" height=\"433\"><\/A><\/P>\n<P>Well, you can research on it (murl.mg) a bit more, It is quite interesting\u2026<\/P>\n<P>So, here we go!, \u201cMUrl\u201d!, a great Oslo DSL Sample! <\/P>\n<P>Thanks Doug for this nice development!<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u201cMUrl\u201d is a textual DSL and runtime for interacting with REST\/HTTP services. It is actually just a great Oslo-DSL sample, as you can download it (all its source code) from MSDN.com: http:\/\/download.microsoft.com\/download\/4\/0\/B\/40B632EC-F201-43EE-8E29-C398A9DA8468\/MUrlSample.msi As long as I know, \u201cMUrl\u201d has been mainly developed by Douglas Purdy. I saw his session at MIX09, which was fabulous; so [&hellip;]<\/p>\n","protected":false},"author":362,"featured_media":12806,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[59,68,74],"class_list":["post-1083","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cesardelatorre","tag-m-language","tag-murl","tag-oslo"],"acf":[],"blog_post_summary":"<p>\u201cMUrl\u201d is a textual DSL and runtime for interacting with REST\/HTTP services. It is actually just a great Oslo-DSL sample, as you can download it (all its source code) from MSDN.com: http:\/\/download.microsoft.com\/download\/4\/0\/B\/40B632EC-F201-43EE-8E29-C398A9DA8468\/MUrlSample.msi As long as I know, \u201cMUrl\u201d has been mainly developed by Douglas Purdy. I saw his session at MIX09, which was fabulous; so [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/posts\/1083","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/users\/362"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/comments?post=1083"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/posts\/1083\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/media\/12806"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/media?parent=1083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/categories?post=1083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/tags?post=1083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}