{"id":1080,"date":"2014-12-31T10:08:53","date_gmt":"2014-12-31T15:08:53","guid":{"rendered":"https:\/\/blogs.mathworks.com\/loren\/?p=1080"},"modified":"2016-08-02T12:57:12","modified_gmt":"2016-08-02T17:57:12","slug":"using-restful-web-service-interface-in-r2014b-matlab","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/loren\/2014\/12\/31\/using-restful-web-service-interface-in-r2014b-matlab\/","title":{"rendered":"Using RESTful Web Service Interface in R2014b MATLAB"},"content":{"rendered":"<p>FT<\/p>\n<div class=\"content\"><!--introduction-->Guest blogger, Kelly Luetkemeyer, who is a software developer at MathWorks, returns with an article on accessing RESTful web services using MATLAB. Kelly's previous articles included <a href=\"https:\/\/blogs.mathworks.com\/loren\/2011\/01\/20\/tracking-a-hurricane-using-web-map-service-wms\/\">Tracking a Hurricane using Web Map Service<\/a> and <a href=\"https:\/\/blogs.mathworks.com\/loren\/2010\/05\/06\/oilslick\/\">Visualizing the Gulf of Mexico Oil Slick using Web Map Service<\/a>. Kelly was the lead developer of the new RESTful web service interface feature in MATLAB.<\/p>\n<p><!--\/introduction--><\/p>\n<h3>Contents<\/h3>\n<div>\n<ul>\n<li><a href=\"#65fbc258-a256-46ee-ae14-f5ac7c49a7f4\">Introduction<\/a><\/li>\n<li><a href=\"#fe208d7c-abd4-45f1-88c3-e681132f444e\">Obtain Job Listings<\/a><\/li>\n<li><a href=\"#2519265e-9e38-4f8a-a335-cecb0f4a26ab\">Learn more about MathWorks from Facebook<\/a><\/li>\n<li><a href=\"#ac70e531-280f-4ff7-a9d7-57e40cdb13cf\">Use RESTful Web Services to obtain Airport and Weather Information<\/a><\/li>\n<li><a href=\"#1069f5b3-036b-42ee-afc3-65733b0bd759\">Display Route from Boston Logan to MathWorks<\/a><\/li>\n<li><a href=\"#02e2b998-d9ef-40f3-b922-3f08acf36e77\">Display High Resolution Image of MathWorks Campus<\/a><\/li>\n<li><a href=\"#4112d0b0-5f3c-4baf-a5c0-bd49646853cf\">Conclusion<\/a><\/li>\n<\/ul>\n<\/div>\n<h4>Introduction<a name=\"65fbc258-a256-46ee-ae14-f5ac7c49a7f4\"><\/a><\/h4>\n<p>In R2104b, MATLAB introduced three new features to access RESTful web services:<\/p>\n<div>\n<ul>\n<li><a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/webread.html\">webread<\/a> - Read content from RESTful web service<\/li>\n<li><a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/websave.html\">websave<\/a> - Save content from RESTful web service to file<\/li>\n<li><a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/weboptions.html\">weboptions<\/a> - Specify parameters for RESTful web service<\/li>\n<\/ul>\n<\/div>\n<p>To illustrate the use of these features, let's do a thought experiment and imagine that you are interested in applying for a software development job at MathWorks. This blog post illustrates how you can use RESTful web services to help in your job search. In particular it shows you how to:<\/p>\n<div>\n<ul>\n<li>Obtain job listings from an RSS feed,<\/li>\n<li>Use the Facebook Graph API to obtain information about MathWorks,<\/li>\n<li>Obtain current weather conditions and airport delays,<\/li>\n<li>Map your route from Boston Logan to MathWorks, and<\/li>\n<li>Obtain and display a high-resolution image of the MathWorks campus<\/li>\n<\/ul>\n<\/div>\n<h4>Obtain Job Listings<a name=\"fe208d7c-abd4-45f1-88c3-e681132f444e\"><\/a><\/h4>\n<p>The first step in your job search is to obtain a listing of all available jobs for your desired location. Job listings are available in an RSS feed, and you can use the function <tt>webread<\/tt> to read the feed. The RSS feed is an XML format. Specify <tt>'xmldom'<\/tt> content type in order to return a Java Document Object Model for easy access to the data. Read the RSS feed and parse the data to create a listing of jobs of interest.<\/p>\n<pre class=\"codeinput\">options = weboptions(<span class=\"string\">'ContentType'<\/span>,<span class=\"string\">'xmldom'<\/span>);\r\nrssURL = <span class=\"string\">'https:\/\/www.mathworks.com\/company\/jobs\/opportunities\/rss.xml'<\/span>;\r\ndom = webread(rssURL, options);\r\n<\/pre>\n<p>Retrieve all the items from the DOM that are tagged <tt>'item'<\/tt>.<\/p>\n<pre class=\"codeinput\">items = dom.getElementsByTagName(<span class=\"string\">'item'<\/span>);\r\nitemsLength = items.getLength;\r\n<\/pre>\n<p>Create a <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/table.html\">table<\/a> to contain the information from the RSS feed. Map the XML tag names to the table variable names by using two cell arrays. Initialize the table using <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/cell2table.html\">cell2table<\/a>.<\/p>\n<pre class=\"codeinput\">tagNames = {<span class=\"string\">'id'<\/span>, <span class=\"string\">'location'<\/span>, <span class=\"string\">'title'<\/span>, <span class=\"string\">'job_function'<\/span>, <span class=\"string\">'job_type'<\/span>};\r\ntableVariableNames = {<span class=\"string\">'Reference'<\/span>, <span class=\"string\">'Location'<\/span>, <span class=\"string\">'Title'<\/span>, <span class=\"string\">'Department'<\/span>, <span class=\"string\">'Type'<\/span>};\r\nemptyItems = cell(itemsLength,length(tableVariableNames));\r\njobsTable = cell2table(emptyItems,<span class=\"string\">'VariableNames'<\/span>,tableVariableNames);\r\n<\/pre>\n<p>Loop through each item and add the information to the table. Use zero-based indexing to obtain the node since the data is contained in a Java object. Use one-based indexing for the table array.<\/p>\n<pre class=\"codeinput\"><span class=\"keyword\">for<\/span> k=0:itemsLength-1\r\n    item = items.item(k);\r\n    <span class=\"keyword\">for<\/span> n = 1:length(tagNames)\r\n        node = item.getElementsByTagName(tagNames{n});\r\n        jobsTable{k+1,n} = {char(node.item(0).getTextContent)};\r\n    <span class=\"keyword\">end<\/span>\r\n<span class=\"keyword\">end<\/span>\r\n<\/pre>\n<p>Select your desired location.<\/p>\n<pre class=\"codeinput\">myLocation = <span class=\"string\">'US-MA-Natick'<\/span>;\r\nrows = strcmpi(jobsTable.Location, myLocation);\r\nnatickJobs = jobsTable(rows,:);\r\nnatickJobs.Location = [];\r\n<\/pre>\n<p>Select your desired department.<\/p>\n<pre class=\"codeinput\">myDepartment = <span class=\"string\">'software development'<\/span>;\r\nrows = strcmpi(natickJobs.Department, myDepartment);\r\nnatickSoftwareJobs = natickJobs(rows,:);\r\nnatickSoftwareJobs.Department = [];\r\n<\/pre>\n<p>Display a table of possible jobs that match your request.<\/p>\n<pre class=\"codeinput\">natickSoftwareJobs\r\n<\/pre>\n<pre class=\"codeoutput\">natickSoftwareJobs = \r\n    Reference                                      Title                                             Type        \r\n    _________    _________________________________________________________________________    ___________________\r\n    '14070'      'MATLAB Editor Software Engineer (Senior) (14070-MCAR)'                      'Experienced'      \r\n    '14064'      'Software Engineer - Graphical Platform (14064-BWAL)'                        'Experienced'      \r\n    '14049'      'Release Engineer (14049-BHIL)'                                              'Experienced'      \r\n    '14028'      'Software Engineer (14028-MCOL)'                                             'Experienced'      \r\n    '14027'      'Software Engineer (14027-MCOL)'                                             'Experienced'      \r\n    '14023'      'Software Developer (14023-MCOL)'                                            'Experienced'      \r\n    '13866'      'Controls Systems Engineer (13866-MCAR)'                                     'Experienced'      \r\n    '13859'      'Software Engineer (13859-MCOL)'                                             'Experienced'      \r\n    '13857'      'Web User Interface Developer (13857-MCOL)'                                  'Experienced'      \r\n    '13856'      'Senior Software Engineer (13856-MCOL)'                                      'Experienced'      \r\n    '13855'      'Software Engineer (13855-MCOL)'                                             'Experienced'      \r\n    '13854'      'Software Engineer - GUI Components (13854-MCOL)'                            'Experienced'      \r\n    '13853'      'Build and Release Engineer - Perl \/ Shell (13853-MCOL)'                     'Experienced'      \r\n    '13851'      'Code Replacement Library Software Engineer (13851-GMAR)'                    'Experienced'      \r\n    '13848'      'Senior Performance Engineer (13848-MCAR)'                                   'Experienced'      \r\n    '13793'      'Software Engineer - MATLAB Development Tools (13793-MCAR)'                  'Experienced'      \r\n    '13792'      'Software Engineer - Desktop \/ Toolbox Integration (13792-MCAR)'             'Experienced'      \r\n    '13791'      'Autonomous Controls Systems Engineer (13791-MCAR)'                          'Experienced'      \r\n    '13789'      'Software Engineer - MATLAB Hardware (13789-MCAR)'                           'Experienced'      \r\n    '13779'      'Web Application Developer (13779-JJUS)'                                     'Experienced'      \r\n    '13778'      'Software Engineer - Cloud Storage (13778-JJUS)'                             'Experienced'      \r\n    '13777'      'Senior Software Engineer - Web Services (13777-JJUS)'                       'Experienced'      \r\n    '13776'      'Senior Software Engineer - MATLAB Online (13776-JJUS)'                      'Experienced'      \r\n    '13775'      'Senior Technical Lead - MATLAB Web Services (13775-JJUS)'                   'Experienced'      \r\n    '13774'      'Java Software Engineer - Support Software Installer (13774-JJUS)'           'Experienced'      \r\n    '13773'      'Java Software Engineer (13773-JJUS)'                                        'Experienced'      \r\n    '13772'      'Mobile Software Engineer (13772-JJUS)'                                      'Experienced'      \r\n    '13752'      'Software Engineer - Numerical Optimization (13752-SMAR)'                    'Experienced'      \r\n    '13751'      'Principal Software Engineer - Data Munging (13751-SMAR)'                    'Experienced'      \r\n    '13750'      'Senior Software Engineer - MATLAB Math (13750-SMAR)'                        'Experienced'      \r\n    '13747'      'Image Algorithms Software Engineer (13747-SMAR)'                            'Experienced'      \r\n    '13746'      'Software Engineer - Data Analysis (13746-SMAR)'                             'Experienced'      \r\n    '13745'      'Data Analysis Tools Developer (13745-SMAR)'                                 'Experienced'      \r\n    '13743'      'Senior Software Engineer - Statistics and Machine Learning (13743-SMAR)'    'Experienced'      \r\n    '13742'      'Senior MATLAB Web UI Engineer (13742-SMAR)'                                 'Experienced'      \r\n    '13734'      'Senior Software Engineer - Application Deployment (13734-MCAR)'             'Experienced'      \r\n    '13733'      'Software Engineer - Compiler Componentization (13733-MCAR)'                 'Experienced'      \r\n    '13732'      'UI Developer - Toolboxes &amp; Addons (13732-MCAR)'                             'Experienced'      \r\n    '13730'      'Software Engineer - C+ (13730-MCAR)'                                        'Experienced'      \r\n    '13729'      'Software Engineer - C++ (13729-MCAR)'                                       'Experienced'      \r\n    '13689'      'Simulink Developer Engineer (13689-KCAR)'                                   'Internships'      \r\n    '13668'      'Co-Op: Design Automation Software Development (13668-KCAR)'                 'Internships'      \r\n    '13660'      'C++ Software Engineer  Algorithms and Code Generation (13660-GMAR)'         'Experienced'      \r\n    '13651'      'Compiler Engineer for FPGA Design (13651-KCAR)'                             'Internships'      \r\n    '13621'      'C++ Software Engineer - User Interfaces and Visualization (13621-BWAL)'     'Experienced'      \r\n    '13613'      'MATLAB Web Applications Engineer - Intern (13613-JJUS)'                     'Internships'      \r\n    '13603'      'C++ Software Engineer Intern (13603-KCAR)'                                  'Internships'      \r\n    '13594'      'Senior MATLAB Test Frameworks Engineer (13594-BHIL)'                        'Experienced'      \r\n    '13593'      'Software Engineer for Design Automation (13593-KKOT)'                       'Internships'      \r\n    '13577'      'Data Tools Development Intern (13577-KCAR)'                                 'Internships'      \r\n    '13569'      'Senior Compiler Engineer (13569-GMAR)'                                      'Experienced'      \r\n    '13566'      'Simulink Compiler Engineering Intern (13566-KCAR)'                          'Internships'      \r\n    '13563'      'LRM Updates to Verilog and SystemVerilog Emitters (13563-KCAR)'             'Internships'      \r\n    '13558'      'Software Engineer  GUI and Hardware Connectivity (13558-GMAR)'              'Experienced'      \r\n    '13545'      'C++ Software Engineer - Graphical User Interfaces (13545-BWAL)'             'Experienced'      \r\n    '13538'      'OAuth \/ LTI Integration Software Intern (13538-KCAR)'                       'Internships'      \r\n    '13532'      'Software Scope Infrastructure Internship (13532-KCAR)'                      'Temps\/Consultants'\r\n    '13531'      'Software Scope Infrastructure Internship (13531-KCAR)'                      'Temps\/Consultants'\r\n    '13530'      'FPGA Prototyping Intern (13530-KCAR)'                                       'Internships'      \r\n    '13529'      'HDL Verifier Intern (13529-KCAR)'                                           'Internships'      \r\n    '13518'      'Communications and Signal Processing HDL Development (13518-KCAR)'          'Internships'      \r\n    '13516'      'FPGA Prototyping for Image, Video and Computer Vision (13516-KCAR)'         'Internships'      \r\n    '13515'      'Audio Intern (13515-KCAR)'                                                  'Internships'      \r\n    '13508'      'C++ Software Developer - Discrete Event Simulation (13508-GMAR)'            'Experienced'      \r\n    '13473'      'C++ Developer (13473-MCAR)'                                                 'Experienced'      \r\n    '13466'      'JavaScript Software Engineer (13466-SMAR)'                                  'Experienced'      \r\n    '13422'      'Release Engineering Intern (13422-KCAR)'                                    'Internships'      \r\n    '13412'      'Web Applications Development Intern (13412-KCAR)'                           'Internships'      \r\n    '13403'      'Documentation Toolsmith (13403-JJUS)'                                       'Experienced'      \r\n    '13393'      'Robotics Software Developer (13393-GMAR)'                                   'Experienced'      \r\n    '12383'      'C++ Software Engineer - Compiler Engineer for MATLAB (12383-MCAR)'          'Experienced'      \r\n    '12382'      'Senior Compiler Engineer LLVM (12382-GMAR)'                                 'Experienced'      \r\n    '12379'      'Senior Software Engineer - Internet Services Platform (12379-JJUS)'         'Experienced'      \r\n    '12377'      'Senior Software Engineer - Graphics \/ OpenGL (12377-SMAR)'                  'Experienced'      \r\n    '12369'      'Build System Software Engineer (12369-BHIL)'                                'Experienced'      \r\n    '12365'      'Test Infrastructure Software Developer (12365-BHIL)'                        'Experienced'      \r\n    '12362'      'Software Engineer - Data Analysis Tools (12362-SMAR)'                       'Experienced'      \r\n    '12358'      'Web UI Developer - MATLAB Editor (12358-MCAR)'                              'Experienced'      \r\n    '12356'      'Software Developer - Graphic Export and Printing (12356-SMAR)'              'Experienced'      \r\n    '12352'      'JavaScript Build Infrastructure Engineer (12352-BHIL)'                      'Experienced'      \r\n    '12351'      'Software Engineer - Maven Build and Deployment (12351-BHIL)'                'Experienced'      \r\n    '12342'      'Web Application Developer (12342-JJUS)'                                     'Experienced'      \r\n    '12324'      'Compiler Engineer - Parallel Computing (12324-GMAR)'                        'Experienced'      \r\n    '12322'      'Web UI Software Engineer (12322-SMAR)'                                      'Experienced'      \r\n    '12320'      'Senior Web Application Developer (12320-JJUS)'                              'Experienced'      \r\n    '12317'      'Senior Software Engineer - Enterprise Solutions (12317-MCAR)'               'Experienced'      \r\n    '12316'      'C++ Software Engineer - Simulink Architecture Group (12316-GMAR)'           'Experienced'      \r\n    '12315'      'Computer Vision Systems Software Engineer (12315-GMAR)'                     'Experienced'      \r\n    '12312'      'Web Application Developer - Groovy on Grails\/Java (12312-BHIL)'             'Experienced'      \r\n    '12308'      'Analog and Mixed Signal Simulation Developer (12308-GMAR)'                  'Experienced'      \r\n    '12305'      'Compiler Engineer (12305-GMAR)'                                             'Experienced'      \r\n    '12304'      'Software Engineer - Data Streaming and Visualization (12304-BWAL)'          'Experienced'      \r\n    '12301'      'C++ Algorithm Optimization Software Engineer (12301-GMAR)'                  'Experienced'      \r\n    '12300'      'Senior Compiler Developer - Auto-generate C from Simulink (12300-GMAR)'     'Experienced'      \r\n    '12284'      'C++ Algorithm Developer - Stateflow (12284-GMAR)'                           'Experienced'      \r\n    '12275'      'C++ Code Generation Software Engineer (12275-GMAR)'                         'Experienced'      \r\n    '12240'      'Java Software Engineer Distributed Application Development (12240-BHIL)'    'Experienced'      \r\n    '12229'      'Senior Engineer, Requirements Modeling and Management (12229-GMAR)'         'Experienced'      \r\n    '12227'      'Senior Engineer, Model Static Analysis (12227-GMAR)'                        'Experienced'      \r\n    '12217'      'Release Engineering Intern (12217-BHIL)'                                    'Internships'      \r\n    '12174'      'Internal Tools Developer (12174-BHIL)'                                      'Experienced'      \r\n    '12159'      'Release Engineer (12159-BHIL)'                                              'Experienced'      \r\n    '12155'      'Web Software Test Infrastructure and Architecture Engineer (12155-BHIL)'    'Experienced'      \r\n    '12072'      'Web GUI Engineer (12072-SMAR)'                                              'Experienced'      \r\n    '12042'      'Web Application Developer -  Commerce Systems (12042-JJUS)'                 'Experienced'      \r\n    '12029'      'Senior Software Engineer - Graphics \/ OpenGL (12029-SMAR)'                  'Experienced'      \r\n    '11941'      'Numerical Simulation Software Engineer (11941-GMAR)'                        'Experienced'      \r\n    '11883'      'Senior Software Engineer, Program Analysis\/Formal Methods (11883-GMAR)'     'Experienced'      \r\n    '11715'      'Product Release Engineer (11715-BHIL)'                                      'New Graduate'     \r\n    '11669'      'Web UI Software Engineer (11669-JJUS)'                                      'Experienced'      \r\n    '11506'      'Support Package for Mobile devices (11506-SMAR)'                            'Internships'      \r\n    '11471'      'DevOps Engineer - Cloud\/SaaS (11471-SMAR)'                                  'Experienced'      \r\n    '11431'      'Senior Compiler Engineer (11431-MCAR)'                                      'Experienced'      \r\n    '11373'      'Web User Interface - Senior Software Developer (11373-GMAR)'                'Experienced'      \r\n    '11302'      'Senior Technical Lead - Statistics \/ Machine Learning (11302-SMAR)'         'Experienced'      \r\n    '11254'      'Senior Software Developer - Graphical Language Editors (11254-BWAL)'        'Experienced'      \r\n    '11087'      'Web MATLAB Desktop UI Developer (11087-MCAR)'                               'Experienced'      \r\n    '10415'      'Senior C++ Compiler Engineer (10415-MCAR)'                                  'Experienced'      \r\n    '10089'      'Senior Software Test Infrastructure Developer (10089-BHIL)'                 'Experienced'      \r\n    '10038'      'MATLAB Software Engineer - Web GUIs (10038-SMAR)'                           'Experienced'      \r\n    '9537'       'Senior Compiler Engineer (9537-MCAR)'                                       'Experienced'      \r\n    '8916'       'MATLAB on the Web - Backend Developer (8916-JJUS)'                          'Experienced'      \r\n    '8904'       'Senior Software Engineer - Web UI Platform (8904-JJUS)'                     'Experienced'      \r\n    '8892'       'Simulink Compiler Engineer (8892-GMAR)'                                     'Experienced'      \r\n<\/pre>\n<p>Perhaps after searching through this list of jobs, you realize that you would prefer an application engineering job. You can do more searches by placing the commands that are illustrated above into a <a href=\"https:\/\/blogs.mathworks.com\/images\/loren\/2014\/jobsReader.m\"><tt>jobsReader<\/tt><\/a> function. The <tt>jobsReader<\/tt> function takes a filename as the first input followed optionally by the location and department strings. You can specify <tt>'all'<\/tt> for either location or department to get a complete listing. Save the content to a file and then use your <tt>jobsReader<\/tt> function. You can save the RSS feed by using <tt>websave<\/tt> to save the contents to a file.<\/p>\n<pre class=\"codeinput\">filename = <span class=\"string\">'rss.xml'<\/span>;\r\nwebsave(filename, rssURL);\r\n<\/pre>\n<p>Specify your new job search criteria and obtain the data from the file.<\/p>\n<pre class=\"codeinput\">myLocation = <span class=\"string\">'US-MA-Natick'<\/span>;\r\nmyDepartment = <span class=\"string\">'Application Engineering'<\/span>;\r\napplicationEngineeringJobs = jobsReader(filename,myLocation,myDepartment)\r\n<\/pre>\n<pre class=\"codeoutput\">applicationEngineeringJobs = \r\n    Reference                                   Title                                        Type     \r\n    _________    ____________________________________________________________________    _____________\r\n    '14075'      'Application Engineer- Hardware-in-the-Loop (14075-SMAR)'               'Experienced'\r\n    '11969'      'Senior Application Engineer (11969-SMAR)'                              'Experienced'\r\n    '11943'      'Principal Application Engineer - Hardware-in-the-Loop (11943-SMAR)'    'Experienced'\r\n<\/pre>\n<p>Rather than saving the content to a file, you can specify a function handle as a content reader for <tt>webread<\/tt>. When the <tt>ContentReader<\/tt> property is specified in <tt>weboptions<\/tt>, <tt>webread<\/tt> downloads the content to a temporary file and reads the file using the specified function.<\/p>\n<p>Specify an anonymous function handle to return application engineering jobs in Natick.<\/p>\n<pre class=\"codeinput\">contentReader = @(filename)jobsReader(filename,myLocation,myDepartment);\r\noptions = weboptions(<span class=\"string\">'ContentReader'<\/span>,contentReader);\r\napplicationEngineeringJobs = webread(rssURL,options)\r\n<\/pre>\n<pre class=\"codeoutput\">applicationEngineeringJobs = \r\n    Reference                                   Title                                        Type     \r\n    _________    ____________________________________________________________________    _____________\r\n    '14075'      'Application Engineer- Hardware-in-the-Loop (14075-SMAR)'               'Experienced'\r\n    '11969'      'Senior Application Engineer (11969-SMAR)'                              'Experienced'\r\n    '11943'      'Principal Application Engineer - Hardware-in-the-Loop (11943-SMAR)'    'Experienced'\r\n<\/pre>\n<h4>Learn more about MathWorks from Facebook<a name=\"2519265e-9e38-4f8a-a335-cecb0f4a26ab\"><\/a><\/h4>\n<p>Use the <a href=\"https:\/\/developers.facebook.com\/docs\/graph-api\">Facebook Graph API<\/a> to obtain more information about MathWorks. The Graph API returns a JSON string. <tt>webread<\/tt> parses the string into a structure.<\/p>\n<pre class=\"codeinput\">facebookAPI = <span class=\"string\">'https:\/\/graph.facebook.com\/'<\/span>;\r\ncompany = <span class=\"string\">'MathWorks'<\/span>;\r\nfacebookURL = [facebookAPI company];\r\nmathworks = webread(facebookURL)\r\n<\/pre>\n<pre class=\"codeoutput\">mathworks = \r\n                     id: '19564567448'\r\n                  about: 'Over one million people around the world speak M...'\r\n               can_post: 0\r\n               category: 'Computers\/technology'\r\n          category_list: [1x1 struct]\r\n               checkins: 2063\r\n       company_overview: 'MathWorks products are used throughout the autom...'\r\n                  cover: [1x1 struct]\r\n            description: 'MATLAB\u00ae is a high-level language and interactive...'\r\n                founded: '1984'\r\n          has_added_app: 0\r\n      is_community_page: 0\r\n           is_published: 1\r\n                  likes: 211377\r\n                   link: 'https:\/\/www.facebook.com\/MathWorks'\r\n               location: [1x1 struct]\r\n                mission: 'Technology\r\n\r\nOur goal is to change the world by a...'\r\n                   name: 'MathWorks'\r\n                parking: [1x1 struct]\r\n                  phone: '(508) 647-7000'\r\n    talking_about_count: 2268\r\n               username: 'MathWorks'\r\n                website: 'https:\/\/www.mathworks.com'\r\n        were_here_count: 2063\r\n<\/pre>\n<p>Display overview information about MathWorks. Use line wrapping to display the text; otherwise it will get trimmed when publishing the blog post. Use the function <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/strsplit.html\">strsplit<\/a> to split the string at each white space into a cell array of strings. Compute indices indicating which elements to print. With the indices, use the function <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/strjoin.html\">strjoin<\/a> to construct the string to print. Use the function <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/strtrim.html\">strtrim<\/a> to ensure that each line begins with a character.<\/p>\n<pre class=\"codeinput\">splitData = strsplit(mathworks.company_overview,<span class=\"string\">' '<\/span>);\r\nmaxLengthOfLine = 80;\r\nlengthOfString = cellfun(@length, splitData) + 1;\r\n<span class=\"keyword\">while<\/span> ~isempty(splitData)\r\n    elementsToPrint = cumsum(lengthOfString) &lt;= maxLengthOfLine;\r\n    <span class=\"keyword\">if<\/span> ~any(elementsToPrint)\r\n       elementsToPrint(1) = true;\r\n    <span class=\"keyword\">end<\/span>\r\n    lineout = strjoin(splitData(elementsToPrint));\r\n    fprintf(<span class=\"string\">'%s\\n'<\/span>, strtrim(char(lineout)));\r\n    splitData = splitData(~elementsToPrint);\r\n    lengthOfString = lengthOfString(~elementsToPrint);\r\n<span class=\"keyword\">end<\/span>\r\n<\/pre>\n<pre class=\"codeoutput\">MathWorks products are used throughout the automotive, aerospace,\r\ncommunications, electronics, and industrial automation industries as\r\nfundamental tools for research and development. They are also used for modeling\r\nand simulation in increasingly technical fields, such as financial services and\r\ncomputational biology. MathWorks software enables the design and development of\r\na wide range of advanced products, including automotive systems, aerospace\r\nflight control and avionics, telecommunications and other electronics\r\nequipment, industrial machinery, and medical devices. More than 5000 colleges\r\nand universities around the world use MathWorks solutions for teaching and\r\nresearch in a broad range of technical disciplines.\r\n<\/pre>\n<p>Display the MathWorks cover source image from Facebook. <tt>webread<\/tt> returns an M-by-N-by-3 image when reading <tt>image\/jpeg<\/tt> content. Use <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/imshow.html\">imshow<\/a> to display the image.<\/p>\n<pre class=\"codeinput\">RGB = webread(mathworks.cover.source);\r\nfigure\r\nimshow(RGB)\r\n<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2014\/R2014b_restful_webservices_01.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<p>You can use <tt>webread<\/tt> to read specific fields from Facebook by specifying a <tt>'fields'<\/tt> query parameter. Use the query parameter syntax to read the <tt>'mission'<\/tt> and <tt>'likes'<\/tt> fields.<\/p>\n<pre class=\"codeinput\">fields = <span class=\"string\">'mission,likes'<\/span>;\r\ndata = webread(facebookURL,<span class=\"string\">'fields'<\/span>,fields)\r\n<\/pre>\n<pre class=\"codeoutput\">data = \r\n    mission: 'Technology\r\n\r\nOur goal is to change the world by accelerating ...'\r\n      likes: 211377\r\n         id: '19564567448'\r\n<\/pre>\n<p>To understand more about MathWorks, print the mission statement. The function <a href=\"https:\/\/blogs.mathworks.com\/images\/loren\/2014\/strprint.m\"><tt>strprint<\/tt><\/a> is a local function created from the code in the previous section to split and print the company overview. In this case, use <tt>strsplit<\/tt> to split the mission statement into sentences.<\/p>\n<pre class=\"codeinput\">sentences = strsplit(data.mission, <span class=\"string\">'.'<\/span>);\r\n<span class=\"keyword\">for<\/span> k = 1:length(sentences)\r\n    fprintf(<span class=\"string\">'\\n'<\/span>)\r\n    <span class=\"keyword\">if<\/span> ~isempty(sentences{k})\r\n        sentence = sprintf(<span class=\"string\">'%s.\\n'<\/span>, sentences{k});\r\n        strprint(sentence)\r\n    <span class=\"keyword\">end<\/span>\r\n<span class=\"keyword\">end<\/span>\r\n<\/pre>\n<pre class=\"codeoutput\">Technology\r\n\r\nOur goal is to change the world by accelerating the pace of\r\ndiscovery, innovation, development, and learning in engineering and science.\r\n\r\nWe work to provide the ultimate computing environment for technical\r\ncomputation, visualization, design, simulation, and implementation.\r\n\r\nWe use this environment to provide innovative solutions in a wide range of\r\napplication areas.\r\n\r\nBusiness\r\n\r\nWe strive to be the leading worldwide developer and supplier of\r\ntechnical computing software.\r\n\r\nOur business activities are characterized by quality, innovation, and\r\ntimeliness; competitive awareness; ethical business practices; and outstanding\r\nservice to our customers.\r\n\r\nHuman\r\n\r\nWe cultivate an enjoyable, vibrant, participatory, and rational work\r\nenvironment that nurtures individual growth, empowerment, and responsibility;\r\nappreciates diversity; encourages initiative and creativity; values teamwork;\r\nshares success; and rewards excellence.\r\n\r\nSocial\r\n\r\nWe actively support our communities and promote social and\r\nenvironmental responsibility.\r\n\r\nLearn more about our Social Mission.\r\n\r\n<\/pre>\n<p>Display the location information to assist in travel planning.<\/p>\n<pre class=\"codeinput\">location = mathworks.location\r\n<\/pre>\n<pre class=\"codeoutput\">location = \r\n         city: 'Natick'\r\n      country: 'United States'\r\n     latitude: 42.3\r\n    longitude: -71.349\r\n        state: 'MA'\r\n       street: '3 Apple Hill Dr'\r\n          zip: '01760'\r\n<\/pre>\n<h4>Use RESTful Web Services to obtain Airport and Weather Information<a name=\"ac70e531-280f-4ff7-a9d7-57e40cdb13cf\"><\/a><\/h4>\n<p>You can use a RESTful web service from the Federal Aviation Administration (FAA) to find out the local weather and determine whether any flight delays exist for the Boston Logan International Airport. The web service allows you to specify JSON format for the output.<\/p>\n<pre class=\"codeinput\">faaURL = <span class=\"string\">'http:\/\/services.faa.gov\/airport\/status\/'<\/span>;\r\nairportCode = <span class=\"string\">'BOS'<\/span>;\r\nurl = [faaURL airportCode];\r\nformat = <span class=\"string\">'application\/json'<\/span>;\r\noptions = weboptions(<span class=\"string\">'Timeout'<\/span>,10);\r\ndata = webread(url,<span class=\"string\">'format'<\/span>,format,options)\r\n<\/pre>\n<pre class=\"codeoutput\">data = \r\n      delay: 'false'\r\n       IATA: 'BOS'\r\n      state: 'Massachusetts'\r\n       name: 'General Edward Lawrence Logan International'\r\n    weather: [1x1 struct]\r\n       ICAO: 'KBOS'\r\n       city: 'Boston'\r\n     status: [1x1 struct]\r\n<\/pre>\n<p>Display the time.<\/p>\n<pre class=\"codeinput\">data.weather.meta\r\n<\/pre>\n<pre class=\"codeoutput\">ans = \r\n     credit: 'NOAA's National Weather Service'\r\n    updated: '8:54 AM Local'\r\n        url: 'http:\/\/weather.gov\/'\r\n<\/pre>\n<p>Display the weather information, including temperature and wind speed.<\/p>\n<pre class=\"codeinput\">data.weather\r\n<\/pre>\n<pre class=\"codeoutput\">ans = \r\n    visibility: 2\r\n       weather: 'Light Rain Fog\/Mist'\r\n          meta: [1x1 struct]\r\n          temp: '43.0 F (6.1 C)'\r\n          wind: 'Northwest at 10.4mph'\r\n<\/pre>\n<p>Display the airport status.<\/p>\n<pre class=\"codeinput\">data.status\r\n<\/pre>\n<pre class=\"codeoutput\">ans = \r\n          reason: 'No known delays for this airport.'\r\n    closureBegin: ''\r\n         endTime: ''\r\n        minDelay: ''\r\n        avgDelay: ''\r\n        maxDelay: ''\r\n      closureEnd: ''\r\n           trend: ''\r\n            type: ''\r\n<\/pre>\n<h4>Display Route from Boston Logan to MathWorks<a name=\"1069f5b3-036b-42ee-afc3-65733b0bd759\"><\/a><\/h4>\n<p>If you have access to the Mapping Toolbox\u2122, you can display a map showing you a route from Boston Logan International Airport to MathWorks. Use the gpxread function to read a sample GPX file that ships with the Mapping Toolbox and contains a route from Boston Logan to MathWorks. Overlay that route onto an OpenSteetMap base layer using the webmap function. Display the route using the wmline function.<\/p>\n<pre class=\"codeinput\">route = gpxread(<span class=\"string\">'sample_route'<\/span>);\r\nwebmap(<span class=\"string\">'openstreetmap'<\/span>)\r\nwmline(route.Latitude,route.Longitude)\r\n<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2014\/R2014b_restful_webservices_02.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<p>Print out turn-by-turn directions.<\/p>\n<pre class=\"codeinput\">turns = route(~cellfun(@isempty, route.Description));\r\n<span class=\"keyword\">for<\/span> k = 1:length(turns)\r\n    fprintf(<span class=\"string\">'%s. %s\\n'<\/span>,num2str(k),turns(k).Description)\r\n<span class=\"keyword\">end<\/span>\r\n<\/pre>\n<pre class=\"codeoutput\">1. Head southeast\r\n2. Keep left at the fork, follow signs for I-90 W\/I-93 S\/Williams Tunnel\/Mass Pike and merge onto I-90 W\r\nPartial toll road\r\n3. Take exit 13 to merge onto MA-30 E\/Cochituate Rd toward Natick\r\nPartial toll road\r\n4. Turn right onto Speen St\r\n5. Merge onto MA-9 E\/Worcester St via the ramp on the left to Boston\r\n6. Slight right onto Apple Hill Dr\r\n7. Turn left toward Apple Hill Dr\r\n8. Take the 1st right onto Apple Hill Dr\r\nDestination will be on the right\r\n9. The MathWorks, Inc., Natick, MA.\r\n<\/pre>\n<h4>Display High Resolution Image of MathWorks Campus<a name=\"02e2b998-d9ef-40f3-b922-3f08acf36e77\"><\/a><\/h4>\n<p>Your final destination is the MathWorks campus. You can obtain a high-resolution image of the area from the United States Geological Survey (USGS) National Map Server using the Web Map Service (WMS) protocol. The function <tt>webread<\/tt> returns an RGB image when reading <tt>'image\/jpeg'<\/tt> content type. Specify the WMS query parameters to obtain the image of interest.<\/p>\n<pre class=\"codeinput\">usgsURL = <span class=\"string\">'http:\/\/raster.nationalmap.gov\/arcgis\/services\/Orthoimagery\/USGS_EROS_Ortho\/ImageServer\/WMSServer'<\/span>;\r\nservice = <span class=\"string\">'WMS'<\/span>;\r\nlayers = <span class=\"string\">'0'<\/span>;\r\ncrs = <span class=\"string\">'CRS:84'<\/span>;\r\ncontentType = <span class=\"string\">'image\/jpeg'<\/span>;\r\nheight = 512;\r\nwidth = 512;\r\nrequest = <span class=\"string\">'GetMap'<\/span>;\r\nlatlim = [42.298530964,42.301131366];\r\nlonlim = [-71.353251832,-71.348120766];\r\nformat = <span class=\"string\">'%12.9f'<\/span>;\r\nbbox = [ <span class=\"keyword\">...<\/span>\r\n    sprintf(format,lonlim(1)) <span class=\"string\">','<\/span> sprintf(format,latlim(1)), <span class=\"string\">','<\/span>, <span class=\"keyword\">...<\/span>\r\n    sprintf(format,lonlim(2)) <span class=\"string\">','<\/span> sprintf(format,latlim(2))];\r\nversion = <span class=\"string\">'1.3.0'<\/span>;\r\nRGB = webread(usgsURL, <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'SERVICE'<\/span>, service, <span class=\"string\">'LAYERS'<\/span>, layers, <span class=\"string\">'CRS'<\/span>, crs, <span class=\"string\">'FORMAT'<\/span>, contentType, <span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'HEIGHT'<\/span>, height', <span class=\"string\">'WIDTH'<\/span>, width, <span class=\"string\">'REQUEST'<\/span>, request, <span class=\"string\">'BBOX'<\/span>, bbox);\r\n<\/pre>\n<p>Display the image.<\/p>\n<pre class=\"codeinput\">figure\r\nimshow(RGB)\r\n<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2014\/R2014b_restful_webservices_03.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<h4>Conclusion<a name=\"4112d0b0-5f3c-4baf-a5c0-bd49646853cf\"><\/a><\/h4>\n<p>I am hopeful that this post gives you an introduction to accessing RESTful web services using MATLAB. There are many RESTful web services available on the Internet. How might you use these tools in your work? Let us know <a href=\"https:\/\/blogs.mathworks.com\/loren\/?p=1080#respond\">here<\/a>.<\/p>\n<p>Best of luck in your job search!<\/p>\n<p><script>\/\/ <![CDATA[\nfunction grabCode_6eff1b39999a41a3968a7a8a33ab1032() {\n        \/\/ Remember the title so we can use it in the new page\n        title = document.title;\n\n        \/\/ Break up these strings so that their presence\n        \/\/ in the Javascript doesn't mess up the search for\n        \/\/ the MATLAB code.\n        t1='6eff1b39999a41a3968a7a8a33ab1032 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 6eff1b39999a41a3968a7a8a33ab1032';\n    \n        b=document.getElementsByTagName('body')[0];\n        i1=b.innerHTML.indexOf(t1)+t1.length;\n        i2=b.innerHTML.indexOf(t2);\n \n        code_string = b.innerHTML.substring(i1, i2);\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\n\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \n        \/\/ in the XML parser.\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\n        \/\/ doesn't go ahead and substitute the less-than character. \n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\n\n        copyright = 'Copyright 2014 The MathWorks, Inc.';\n\n        w = window.open();\n        d = w.document;\n        d.write('\n\n\n\n<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\n\n\n\n\n\\n');\n\n        d.title = title + ' (MATLAB code)';\n        d.close();\n    }\n\/\/ ]]><\/script><\/p>\n<p style=\"text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;\">\n<a><span style=\"font-size: x-small; font-style: italic;\">Get<br \/>\nthe MATLAB code<noscript>(requires JavaScript)<\/noscript><\/span><\/a><\/p>\n<p>Published with MATLAB\u00ae R2014b<\/p>\n<\/div>\n<p><!--\n6eff1b39999a41a3968a7a8a33ab1032 ##### SOURCE BEGIN #####\n%% Using RESTful Web Service Interface in R2014b MATLAB\n%\n% Guest blogger, Kelly Luetkemeyer, who is a software developer at\n% MathWorks, returns with an article on accessing RESTful web services\n% using MATLAB. Kelly's previous articles included <https:\/\/blogs.mathworks.com\/loren\/2011\/01\/20\/tracking-a-hurricane-using-web-map-service-wms\/ Tracking a Hurricane using Web Map Service>\n% and <https:\/\/blogs.mathworks.com\/loren\/2010\/05\/06\/oilslick\/ Visualizing % the Gulf of Mexico Oil Slick using Web Map Service>. Kelly was the lead\n% developer of the new RESTful web service interface feature in\n% MATLAB.\n\n%% Introduction\n% In R2104b, MATLAB introduced three new features to access RESTful web\n% services:\n\n%%\n%\n% * <https:\/\/www.mathworks.com\/help\/matlab\/ref\/webread.html webread> - Read content from RESTful web service\n% * <https:\/\/www.mathworks.com\/help\/matlab\/ref\/websave.html websave> - Save content from RESTful web service to file\n% * <https:\/\/www.mathworks.com\/help\/matlab\/ref\/weboptions.html weboptions> - Specify parameters for RESTful web service\n%\n% To illustrate the use of these features, let's do a thought experiment\n% and imagine that you are interested in applying for a software\n% development job at MathWorks. This blog post illustrates how you can use\n% RESTful web services to help in your job search. In particular it shows\n% you how to:\n%\n% * Obtain job listings from an RSS feed,\n% * Use the Facebook Graph API to obtain information about MathWorks,\n% * Obtain current weather conditions and airport delays,\n% * Map your route from Boston Logan to MathWorks, and\n% * Obtain and display a high-resolution image of the MathWorks campus\n\n%% Obtain Job Listings\n% The first step in your job search is to obtain a listing of all available\n% jobs for your desired location. Job listings are available in an RSS\n% feed, and you can use the function |webread| to read the feed.  The RSS\n% feed is an XML format. Specify |'xmldom'| content type in order to return\n% a Java Document Object Model for easy access to the data. Read the RSS\n% feed and parse the data to create a listing of jobs of interest.\noptions = weboptions('ContentType','xmldom');\nrssURL = 'https:\/\/www.mathworks.com\/company\/jobs\/opportunities\/rss.xml';\ndom = webread(rssURL, options);\n\n%%\n% Retrieve all the items from the DOM that are tagged |'item'|.\nitems = dom.getElementsByTagName('item');\nitemsLength = items.getLength;\n\n%%\n% Create a <https:\/\/www.mathworks.com\/help\/matlab\/ref\/table.html table> to\n% contain the information from the RSS feed. Map the XML tag names to the\n% table variable names by using two cell arrays. Initialize the table\n% using <https:\/\/www.mathworks.com\/help\/matlab\/ref\/cell2table.html cell2table>.\ntagNames = {'id', 'location', 'title', 'job_function', 'job_type'};\ntableVariableNames = {'Reference', 'Location', 'Title', 'Department', 'Type'};\nemptyItems = cell(itemsLength,length(tableVariableNames));\njobsTable = cell2table(emptyItems,'VariableNames',tableVariableNames);\n\n%%\n% Loop through each item and add the information to the table. Use\n% zero-based indexing to obtain the node since the data is contained in a\n% Java object. Use one-based indexing for the table array.\nfor k=0:itemsLength-1\nitem = items.item(k);\nfor n = 1:length(tagNames)\nnode = item.getElementsByTagName(tagNames{n});\njobsTable{k+1,n} = {char(node.item(0).getTextContent)};\nend\nend\n\n%%\n% Select your desired location.\nmyLocation = 'US-MA-Natick';\nrows = strcmpi(jobsTable.Location, myLocation);\nnatickJobs = jobsTable(rows,:);\nnatickJobs.Location = [];\n\n%%\n% Select your desired department.\nmyDepartment = 'software development';\nrows = strcmpi(natickJobs.Department, myDepartment);\nnatickSoftwareJobs = natickJobs(rows,:);\nnatickSoftwareJobs.Department = [];\n\n%%\n% Display a table of possible jobs that match your request.\nnatickSoftwareJobs\n\n%%\n% Perhaps after searching through this list of jobs, you realize that you\n% would prefer an application engineering job. You can do more searches by\n% placing the commands that are illustrated above into a\n% <https:\/\/blogs.mathworks.com\/images\/loren\/2014\/jobsReader.m % |jobsReader|> function. The |jobsReader| function takes a filename as the\n% first input followed optionally by the location and department strings.\n% You can specify |'all'| for either location or department to get a\n% complete listing. Save the content to a file and then use your\n% |jobsReader| function. You can save the RSS feed by using |websave| to\n% save the contents to a file.\nfilename = 'rss.xml';\nwebsave(filename, rssURL);\n\n%%\n% Specify your new job search criteria and obtain the data from the file.\nmyLocation = 'US-MA-Natick';\nmyDepartment = 'Application Engineering';\napplicationEngineeringJobs = jobsReader(filename,myLocation,myDepartment)\n\n%%\n% Rather than saving the content to a file, you can specify a function handle\n% as a content reader for |webread|. When the |ContentReader| property is\n% specified in |weboptions|, |webread| downloads the content to a temporary\n% file and reads the file using the specified function.\n%\n% Specify an anonymous function handle to return application engineering\n% jobs in Natick.\ncontentReader = @(filename)jobsReader(filename,myLocation,myDepartment);\noptions = weboptions('ContentReader',contentReader);\napplicationEngineeringJobs = webread(rssURL,options)\n\n%% Learn more about MathWorks from Facebook\n% Use the <https:\/\/developers.facebook.com\/docs\/graph-api Facebook Graph API> to obtain more information about MathWorks.\n% The Graph API returns a JSON string. |webread| parses the string into a\n% structure.\nfacebookAPI = 'https:\/\/graph.facebook.com\/';\ncompany = 'MathWorks';\nfacebookURL = [facebookAPI company];\nmathworks = webread(facebookURL)\n\n%%\n% Display overview information about MathWorks. Use line wrapping to\n% display the text; otherwise it will get trimmed when publishing the blog\n% post. Use the function\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/strsplit.html strsplit> to\n% split the string at each white space into a cell array of strings.\n% Compute indices indicating which elements to print. With the indices,\n% use the function <https:\/\/www.mathworks.com\/help\/matlab\/ref\/strjoin.html strjoin>\n% to construct the string to print. Use the function\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/strtrim.html strtrim> to ensure\n% that each line begins with a character.\nsplitData = strsplit(mathworks.company_overview,' ');\nmaxLengthOfLine = 80;\nlengthOfString = cellfun(@length, splitData) + 1;\nwhile ~isempty(splitData)\nelementsToPrint = cumsum(lengthOfString) <= maxLengthOfLine;\nif ~any(elementsToPrint)\nelementsToPrint(1) = true;\nend\nlineout = strjoin(splitData(elementsToPrint));\nfprintf('%s\\n', strtrim(char(lineout)));\nsplitData = splitData(~elementsToPrint);\nlengthOfString = lengthOfString(~elementsToPrint);\nend\n\n%%\n% Display the MathWorks cover source image from Facebook.\n% |webread| returns an M-by-N-by-3 image when reading |image\/jpeg|\n% content. Use <https:\/\/www.mathworks.com\/help\/matlab\/ref\/imshow.html imshow> to display the image.\nRGB = webread(mathworks.cover.source);\nfigure\nimshow(RGB)\n\n%%\n% You can use |webread| to read specific fields from Facebook by specifying\n% a |'fields'| query parameter. Use the query parameter syntax to read the\n% |'mission'| and |'likes'| fields.\nfields = 'mission,likes';\ndata = webread(facebookURL,'fields',fields)\n\n%%\n% To understand more about MathWorks, print the mission statement. The\n% function <https:\/\/blogs.mathworks.com\/images\/loren\/2014\/strprint.m % |strprint|> is a local function created from the code in the previous\n% section to split and print the company overview. In this case, use\n% |strsplit| to split the mission statement into sentences.\nsentences = strsplit(data.mission, '.');\nfor k = 1:length(sentences)\nfprintf('\\n')\nif ~isempty(sentences{k})\nsentence = sprintf('%s.\\n', sentences{k});\nstrprint(sentence)\nend\nend\n\n%%\n% Display the location information to assist in travel planning.\nlocation = mathworks.location\n\n%% Use RESTful Web Services to obtain Airport and Weather Information\n% You can use a RESTful web service from the Federal Aviation\n% Administration (FAA) to find out the local weather and determine whether\n% any flight delays exist for the Boston Logan International Airport. The\n% web service allows you to specify JSON format for the output.\nfaaURL = 'http:\/\/services.faa.gov\/airport\/status\/';\nairportCode = 'BOS';\nurl = [faaURL airportCode];\nformat = 'application\/json';\noptions = weboptions('Timeout',10);\ndata = webread(url,'format',format,options)\n\n%%\n% Display the time.\ndata.weather.meta\n\n%%\n% Display the weather information, including temperature and wind speed.\ndata.weather\n\n%%\n% Display the airport status.\ndata.status\n\n%% Display Route from Boston Logan to MathWorks\n% If you have access to the Mapping Toolbox(TM), you can display a map\n% showing you a route from Boston Logan International Airport to MathWorks.\n% Use the <https:\/\/www.mathworks.com\/help\/matlab\/ref\/gpxread.html gpxread>\n% function to read a sample GPX file that ships with the Mapping Toolbox\n% and contains a route from Boston Logan to MathWorks. Overlay that route\n% onto an OpenSteetMap base layer using the <https:\/\/www.mathworks.com\/help\/matlab\/ref\/webmap.html webmap> function.\n% Display the route using the\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/wmline.html wmline> function.\nroute = gpxread('sample_route');\nwebmap('openstreetmap')\nwmline(route.Latitude,route.Longitude)\n\n%%\n% Print out turn-by-turn directions.\nturns = route(~cellfun(@isempty, route.Description));\nfor k = 1:length(turns)\nfprintf('%s. %s\\n',num2str(k),turns(k).Description)\nend\n\n%% Display High Resolution Image of MathWorks Campus\n% Your final destination is the MathWorks campus. You can obtain a\n% high-resolution image of the area from the United States Geological\n% Survey (USGS) National Map Server using the Web Map Service (WMS) protocol.\n% The function |webread| returns an RGB image when reading |'image\/jpeg'|\n% content type. Specify the WMS query parameters to obtain the image of\n% interest.\nusgsURL = 'http:\/\/raster.nationalmap.gov\/arcgis\/services\/Orthoimagery\/USGS_EROS_Ortho\/ImageServer\/WMSServer';\nservice = 'WMS';\nlayers = '0';\ncrs = 'CRS:84';\ncontentType = 'image\/jpeg';\nheight = 512;\nwidth = 512;\nrequest = 'GetMap';\nlatlim = [42.298530964,42.301131366];\nlonlim = [-71.353251832,-71.348120766];\nformat = '%12.9f';\nbbox = [ ...\nsprintf(format,lonlim(1)) ',' sprintf(format,latlim(1)), ',', ...\nsprintf(format,lonlim(2)) ',' sprintf(format,latlim(2))];\nversion = '1.3.0';\nRGB = webread(usgsURL, ...\n'SERVICE', service, 'LAYERS', layers, 'CRS', crs, 'FORMAT', contentType, ...\n'HEIGHT', height', 'WIDTH', width, 'REQUEST', request, 'BBOX', bbox);\n\n%%\n% Display the image.\nfigure\nimshow(RGB)\n\n%% Conclusion\n% I am hopeful that this post gives you an introduction to accessing\n% RESTful web services using MATLAB. There are many RESTful web services\n% available on the Internet. How might you use these tools in your work?\n% Let us know <https:\/\/blogs.mathworks.com\/loren\/?p=1080#respond here>.\n%\n% Best of luck in your job search!\n\n##### SOURCE END ##### 6eff1b39999a41a3968a7a8a33ab1032\n--><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2014\/R2014b_restful_webservices_03.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p><!--introduction-->Guest blogger, Kelly Luetkemeyer, who is a software developer at MathWorks, returns with an article on accessing RESTful web services using MATLAB. Kelly's previous articles included <a href=\"https:\/\/blogs.mathworks.com\/loren\/2011\/01\/20\/tracking-a-hurricane-using-web-map-service-wms\/\">Tracking a Hurricane using Web Map Service<\/a> and <a href=\"https:\/\/blogs.mathworks.com\/loren\/2010\/05\/06\/oilslick\/\">Visualizing the Gulf of Mexico Oil Slick using Web Map Service<\/a>. Kelly was the lead developer of the new RESTful web service interface feature in MATLAB.<\/p>\n<p><!--\/introduction-->... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/loren\/2014\/12\/31\/using-restful-web-service-interface-in-r2014b-matlab\/\">read more >><\/a><\/p>\n","protected":false},"author":39,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/1080"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/users\/39"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/comments?post=1080"}],"version-history":[{"count":3,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/1080\/revisions"}],"predecessor-version":[{"id":1883,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/1080\/revisions\/1883"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/media?parent=1080"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/categories?post=1080"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/tags?post=1080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}