![]() |
Table of Contents
net/httpFor REST services using HTTP GET and/or POST the Ruby module net/http can be used to access the service. HTTP GETFor services available through a HTTP GET request, for example WSDbfetch (REST): # Load libraries require 'net/http' require 'uri' # Base URL for service baseUrl = 'http://www.ebi.ac.uk/Tools/webservices/rest/dbfetch' # Defaults dbName = 'uniprot' entryId = 'wap_rat' format = nil # Split URL into components baseUri = URI.parse(baseUrl) # Create a HTTP connection httpConn = Net::HTTP.new(baseUri.host, baseUri.port) # Build the path for the resource reqPath = baseUri.path + '/' + dbName + '/' + entryId if format != nil reqPath += '/' + format end # Get the entry resp, data = httpConn.get(reqPath) # Print the result puts data HTTP POSTFor services which require the use of a HTTP POST request, for example WSWUBlast (see REST tutorial): # Tool name toolName = 'wublast' # Query sequence seq = ">Q8E5Q5_STRA3 MKLSKRYRFWQKVIKALGVLALIATLVLVVYLYKLGILNDSNELKDLVHKYEFWGPMIFI VAQIVQIVFPVIPGGVTTVAGFLIFGPTLGFIYNYIGIIIGSVILFWLVKFYGRKFVLLF MDQKTFDKYESKLETSGYEKFFIFCMASPISPADIMVMITGLSNMSIKRFVTIIMITKPI SIIGYSYLWIYGGDILKNFLN" # Structure containing parameters params = { 'tool' => toolName, 'srchType' => 'interactive', 'sequence' => seq, 'program' => 'blastp', 'database' => 'swissprot', 'email' => 'your@email' } # Build the path for the resource submitUrl = baseUrl + '/submit' # Submit the job resp, jobId = Net::HTTP.post_form(URI(submitUrl), params) # Print the job identifier puts jobId ExamplesSample ClientsMost REST Web Services at EMBL-EBI have sample clients which provide command-line access to the service and example code. For Ruby some of the clients are based on net/http, for example:
![]() |