All docs This doc

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

iconfalse

The contents on this page is under review!

This tutorial will guide you on how to expose an RDF datasource as a data service using the Create New Data Service wizard. To demonstrate this feature, we will use a sample RDF file that is shipped with WSO2 EI by default. Given below are the details of this datasource: 

...

  1. Click Add New Query and enter the following details:

    Query IDGetMoviebyGenre
    DatasourceRDF
    SPARQL

    In this field, enter the sparql query describing the data that should be retrieved from the RDF datasource. We will use the following query:

    Code Block
    PREFIX cd: <http://www.popular.movies/cd#>
     
    SELECT ?title ?director ?year ?genre ?actor 
    WHERE {   
          ?movie cd:title ?title. 
          ?movie cd:director ?director. 
          ?movie cd:year ?year. 
          ?movie cd:genre ?genre. 
          ?movie cd:actor ?actor.
    }
  2. The input mapping section is used to specify the type of input that should be given in order to get the output result. Click Add New Input Mapping to start creating the input mapping. We will create an input mapping for 'genre', which will allow us to query for data based on the genre of the movie.

    Mapping Namegenre
    Sparql TypeString
  3. Now let's specify output mappings to specify how the data fetched from the query should be displayed. We will create output mappings for all the types of data in the RDF file:  title, director, year, genre and actor. Follow the steps given below.
    1. Start by giving the following information:

      Output typeYou can select XML, JSON or RDF. We will use XMLXML for this tutorial. This specifies the format in which the query results should be presented. 
      Grouped by elementEnter Movies. This will be the XML element that will group the query result.
      Row NameEnter Movie. This is the XML element that should group each individual result.
    2. Click Add New Output Mapping to start creating the output mapping for the title column. 
    3. Click Add to save the output mapping. You will now have one output mapping listed for the GetMoviesbyGenre query.
    4. Now, add the following output mappings:

      Mapping TypeElement NameDatasource TypeDatasource Column NameParameter TypeSchema Type
      ElementtitleColumntitleSCALARstring
      ElementdirectorColumndirectorSCALARstring
      ElementyearColumnyearSCALARstring
      ElementgenreColumngenreSCALARstring
      ElementactorColumnactorSCALARstring
    5. Click Main Configuration to return to the Query screen.
  4. Save the query, and click Next to go to the Operations screen.

...

You can now invoke the data service query using SOAP.

...

Creating a REST resource to invoke the query

Now, let's create REST resources to invoke the query created above. Alternatively, you can create SOAP operations to invoke the queries. See the previous section for instructions.

...

Code Block
curl -X GET http://localhost:8280/services/RDFDataService.HTTPEndpoint/Movies/Drama

This will return the response in XML.