DPLA API Tutorial

This tutorial was originally developed for use with the Hacking DPLA at TCDL event held Sunday, April 27, 2014, at the University of Texas at Austin’s Perry-Castañeda Library. Anyone is welcome to reuse, modify, or adapt this tutorial for educational purposes. For other uses, please contact Danielle Cunniff Plumer, danielle@dcplumer.com.

Introduction

The Digital Public Library of America (DPLA) is a project to bring together the riches of America’s libraries, archives, and museums, and make them freely available to the world. DPLA has multiple roles:

  • DPLA is a portal that brings together approximately six million items from across the country, with more items added regularly, and presents them to visitors in a variety of contexts, including maps, timelines, and exhibits.
  • DPLA is also a platform that allows developers to access and reuse the metadata from those items, with a robust application programming interface (API). One of the beauties of the DPLA community is that developers have already contributed libraries that simplify using the API. Libraries, in this sense, are bits of code that define functions and methods that can be used to interact with the API and interpret the data returned by the API.  In the DPLA Developer’s Codex, these are called “wrappers,” because they “wrap” the DPLA API, which is JSON-LD (a lightweight Linked Data format), in a variety of other types of code, including Java, Node.js, PHP, Ruby, and Python. If you’re comfortable developing code in any one of those languages, you’re in good shape.
  • Finally, DPLA is an advocate for making our common cultural heritage openly available to the public, in the best tradition of libraries, archives, and museums. If you work with cultural heritage materials in any capacity, you are invited to join the DPLA community to help make this happen.

In this tutorial, you will be developing a simple search form using the DPLA API. We’ll be working in HTML and PHP; no previous coding experience is required. At the end of the tutorial, you’ll have a working search form that displays results from the API that you can reuse on your personal webpage and perhaps in other contexts, though you might have to do a bit more work to include it in a blog or other content management system. This tutorial is intended to be self-paced, but we recommend that you go through it with other people who are also interested in learning how the DPLA API works. It’s more fun that way, and you might get some help if you get stuck.

Before We Start

For this tutorial, you will need:

  • A plain-text editor. Notepad++ is a good choice for Windows users. Sublime Text (http://www.sublimetext.com) and BBEdit (http://www.barebones.com/products/bbedit/) are possibilities for Mac users; free trial versions are available. A full-blown editor such as Dreamweaver or the Eclipse IDE is optional but not necessary (and might even get in the way).
  • A development environment in which to test your code. This might be:
  • A DPLA API Key. The instructions to get your own personal API Key are available at http://dp.la/info/developers/codex/policies/#get-a-key, along with a lot of other useful information about the API.
    • To get a key:
      • If you’re using a Mac with OS X, you can open up the Terminal (in Applications/Utilities) and type the command curl -v -XPOST http://api.dp.la/v2/api_key/YOUR_EMAIL@example.com, where you insert your preferred email address. Don’t just copy and paste this, because I imagine that YOUR_EMAIL@example.com has received many API Keys already.
      • If you’re using Windows, you could install CuRL for this step, though many alternatives exist.
    • Now check your email. You should have received an email from api-support@dp.la with your new API key. Save it somewhere for future use.
    • If you want to try your new key out immediately, open a new browser tab and paste the following information into the URL:http://api.dp.la/v2/items?q=weasels&api_key=YOURAPIKEY0000000000000000000001. Insert the API Key you just received instead of using the placeholder (naturally) and hit Enter. You will get back a screen full of text, which you probably won’t be able to read. There’s some explanation of what you’re seeing at http://dp.la/info/developers/codex/api-basics/, but you don’t really need to be able to read the response yourself. That’s what computers are for.

Simple DPLA Search

We will start this tutorial by writing a simple HTML form to search DPLA without using the API. This simple search is modeled on (and re-uses some code from) the DPLA Search Widget developed by Dean Farrell and Josh Wilson. There’s some discussion about how to work with and modify this tool at the blog post “Hacking DPLA at TCDL.” The search form you build will look like this:

simplesearch-2

 

 

 

Open up your plain-text editor and start an HTML page. Copy and paste the following code:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Simple DPLA Search Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body>
This is where the search form will go.
</body>
</html>

Save this file as DPLA-simple-search.html on your computer. Now open the file in a new tab in your web browser. In most browsers, you can just select File > Open File and navigate to the file you want to view. As you continue to work through this tutorial, you will need to reload the file periodically to be sure that it reflects the changes you have saved.

simplesearch-1

 

 

 

 

 

 

This file is what is sometimes called a “stub,” a simple way to get started with a new coding project.

In your plain text editor, you now need to create a form. The code for this is very simple. Copy and paste this in place of the line “This is where the search form will go.”

<form action="http://dp.la/search" method="get" target="_blank">
 <input name="q" type="text" placeholder="Search DPLA" />
 <input type="submit" title="Search" value="Search" />
</form>

This tells the browser to insert a simple search form that allows people to enter one or more search term(s) and then sends a search query to the DPLA’s search portal, showing the results in a new window or tab.

Next, add an image. Before the form, insert the following line:

<img src="http://dp.la/info/wp-content/uploads/2013/12/dpla-search-widget-logo.png" width="190" height="52" />

This inserts the DPLA logo above the search form.

The final step is to add the formatting, which is done through a Cascading Style Sheet (CSS) file. You don’t have to write it, just insert the link to an existing file that has already been created. Before the </head> tag, on line 7 of your HTML file, insert a new line containing:

<link href="http://dp.la/info/wp-content/uploads/2013/12/dpla-search-widget.css" rel="stylesheet" type="text/css">

Next you need to insert a <div>, which tells the browser to look at a specific portion of the stylesheet to get the formatting for the form. After the line with the <body> tag, and before the line that inserts the DPLA logo, add the line:

<div id="dpla_search_widget">

Then, after the </form> line and before the </body> line, insert a new line:

</div>

Save your file and view it again in your browser. Test it out! If you have an Internet connection, it should allow you to search the DPLA portal.

Adding the API

Your simple search form uses the standard DPLA search, encoded in <form action="http://dp.la/search">, which sends the query in our input to the DPLA portal to perform a search. We can replace this URL with the URL for the API search, http://api.dp.la/v2/items?q=. Make this change, and save the file as dpla-api-search.html on your computer. Open the new file in your browser and test the search again by entering in a new query term and pressing submit.

On testing the new code, you should get the response:

{"message":"Unauthorized: Missing, invalid or inactive api_key"}

To fix this, you need to add your API Key to the form input. You will be adding this as a “hidden” input, after the line for the “Search DPLA” input and before the “Submit” input. Insert the line:

<input type="hidden" name="api_key" value="YOURAPIKEY0000000000000000000001">

Using your own API key, of course.

Now save the line and try opening the file and running the search again. In a new tab or window, you should see a screen full of text. Depending on which browser you use, it might be structured text or it might appear as a solid block of text. In either case, this is not an error. You have successfully gotten a response from the DPLA API!

To make sense of the response, you might want to look at http://dp.la/info/developers/codex/responses/, which presents the response as structured text, and http://dp.la/info/developers/codex/responses/field-reference/, where the various fields that are returned are explained. We’ll look at a few of the fields in the next step, where we interpret the response in order to format it in the browser.

Interpreting the Response

Before we can begin this section, however, we need to change technologies. We’ve been working in straight HTML, which is a rendered language. That is, a web browser is programmed to read your code and format it for easy reading on the screen. To make sense of the response you are seeing from the DPLA API, we need to interpret the results. The language we will use for that is PHP, a fairly lightweight server-side scripting language. In order to make PHP code readable, we need more than just a browser; we need a web server capable of interpreting the code and creating the HTML for a browser to render.

At this point, you should launch XAMPP or MAMP on your computer. This will start up a webserver on your computer capable of interpreting PHP. This will simplify the job of testing our PHP code, saving you the task of uploading the code to a server somewhere every time you change a line (although you can do that, if you prefer).

You need to create a new directory on your computer, within the XAMPP or MAMP application directory, in which to save your PHP code.

  • On a Macintosh, running MAMP, the location will probably be /Applications/MAMP/bin. Inside the /bin directory, create a new directory called dpla-search. Move or copy your dpla-simple-search.html and dpla-api-search.html files there.
  • On a Windows, running XAMPP, the location will probably by C:\xampp\htdocs. Inside the \htdocs directory, create a new directory called dpla-search. Move or copy your dpla-simple-search.html and dpla-api-search.html files there.

Next, you need to convert your dpla-api-search.html file to PHP. In your plain text editor, add the following lines immediate after the <body> and before the </body> tags:

<?php
?>

The body of your code should now look like this:

<body>
<?php
<div id="dpla_search_widget">
<img src="http://dp.la/info/wp-content/uploads/2013/12/dpla-search-widget-logo.png" width="190" height="52" longdesc="http://dp.la" />
<form action="http://api.dp.la/v2/items?q=" method="get" target="_blank">
  <input name="q" type="text" placeholder="Search DPLA" />
  <input type="hidden" name="api_key" value="YOURAPIKEY0000000000000000000001">
  <input type="submit" title="Search" value="Search" />
</form>
</div>
?>
</body>

PHP actually won’t actually know what to do with the HTML markup, however, because the markup needs to be rendered in a browser. We therefore need to tell PHP to send the HTML markup to the browser verbatim, which is done by enclosing every line in an echo command.

At the beginning of every line, insert echo ' and at the end of the line insert ';

For example:

echo '<div id="dpla_search_widget">';

Then save the file as dpla-api-search.php. Note that your plain text editor may change the colors of the text when you start adding the PHP markup or when you save it; this is not an error.

At this point, go into your webbrowser and open the file through the local server that MAMP or XAMPP has launched.

  • The MAMP URL is probably: http://localhost:8888/MAMP/dpla-search/dpla-api-search.php
  • The XAMPP URL is probably: http://localhost/dpla-search/dpla-api-search.php

The form should look exactly the same as it did when you looked at the straight HTML version. In fact, if your web browser allows you to “View Source,” you will note that the markup is exactly the same as it was in the HTML version, with perhaps some formatting changes. This is because PHP has passed the markup verbatim to the browser, because of the echo commands.

If you don’t see anything at all, there’s probably an error in your code. Common errors include omitting a '; at the end of a line, or using a curly quote instead of a straight quote (this can happen easily with copy and paste).

However, we still need to make some changes to the code. Among other things, we don’t really want the API Key to be visible in the page source. You don’t need to guard your DPLA API Key as carefully as you might a key from a commercial entity or vendor, but it’s still better not to leave it where anybody can steal it. We also need to make sure that PHP can read the query that is entered in the form in order to correctly pass it to the DPLA API and interpret the subsequent response.

Note: because the code starts to get complicated fairly rapidly at this point, you might want to compare your code to a finished version of the dpla-api-search.php code, especially if you experience problems. The finished code is available at https://github.com/dcplumer/dpla-search-tutorial/blob/master/dpla-api-search.php.

Delete the lines containing the form you originally created. Replace them with these lines:

$self = $_SERVER['PHP_SELF'];
$form = '           
  <form name="dpla_widget" method="post" action="'.$self.'">           
  <input type="text" name="q" placeholder="Search DPLA">
  <input type="submit" name="append" value="Search" >
</form>';

This may seem like a step backwards. There’s no use of the DPLA API at all! Instead, what we are doing is creating two variables for PHP, $self and $form. $self tells PHP not to send the query anywhere but simply to store it. $form tells PHP to save the form itself in case it is needed.

Then we add an IF-THEN-ELSE command immediately after the form:

if(isset($_POST['append'])){
  $query = $_POST['q'];
  $url = "http://api.dp.la/v2/items?q=".$query.'&api_key=YOURAPIKEY0000000000000000000001';
  echo $form; 
  echo $url;
}else{
  echo $form; 
  }

Insert your API Key instead of YOURAPIKEY0000000000000000000001

We can interpret this command to mean “If a query has been entered and the submit button has been pressed, save the text that was entered in the query box in the variable $query and construct a search URL that includes both the query and the API key.”

Save the file and try opening it in your web browser, using the localhost URL you identified above. Enter a query and press submit. You should see the URL that would be passed to the DPLA API appear on the screen. This is because we told PHP to echo the form and the URL, but not to do anything else with them.

Now we can test for a few possible issues. First, reload the form. Press the submit button without entering a query. You should get a URL of the form:

http://api.dp.la/v2/items?q=&YOURAPIKEY0000000000000000000001

Try opening a new tab in your web browser and entering that URL. You will get a screen full of text, as before, but note that it starts with the text "count": and a very large number. Congratulations! You have just found every record in the DPLA index! We clearly need to suppress “empty” queries. Change the first line of your new search form to:

if(!empty($_POST['q']) && isset($_POST['append'])){

This checks to make sure that a query has actually been entered (!empty means “is not empty”) as well as that the submit button has been pressed (&& means “and”).

Another error we can easily anticipate is related to the way PHP encodes spaces and other special characters in the query. Try reloading the form and entering the query “Texas Star.” The URL that is generated includes the space. Similarly, special characters such as & and ? are encoded verbatim. While the DPLA API is remarkably tolerant of these issues, we can see what behavior it prefers if we search the DPLA portal directly. The query “Texas & the lone star?” is encoded as “Texas+%26+the+lone+star%3F”. Such an encoding prevents some subtle mistakes from creeping in later on, so we should add a bit of code to clean our query before we send it to the DPLA API.

Replace your IF-THEN-ELSE command with the following:

if(isset($_POST['append'])){
  $query = $_POST['q'];
  $cquery = str_replace(' ', '+', $query);
  $cquery = str_replace('?', '%26', $cquery);
  $cquery = str_replace('&', '%3F', $cquery);
  $url = "http://api.dp.la/v2/items?q=".$cquery.'&api_key=YOURAPIKEY0000000000000000000001';
  echo $form; 
  echo $url;
}else{
  echo $form; 
  }

There are cleaner ways to accomplish this using other PHP commands, but this will work for now. The idea of testing your code against the DPLA portal as you work is the important point to remember. Errors will sneak in despite your best efforts, but testing will help minimize the damage. Part of the reason for having a unique personal API Key is so that DPLA staff can contact you if the errors start to become a problem for them.

Having developed the search input form thus far, we should try to send the result to the DPLA for processing. For this portion of the code, we are going to modify some PHP previously developed by Eric Frierson, efrierson@ebsco.com, for use in the EBSCO Discovery Service and DPLA Highlights app. Eric has commented his code, which is a good practice to follow. In PHP, comments are marked by //.

Remove the line

  echo $url;

We won’t need it any more, and it uglifies our search results.

Insert the following lines after the  echo '</div>'; line following your search form:

// Open the Curl session
$session = curl_init($url);
// Don't return HTTP headers
curl_setopt($session, CURLOPT_HEADER, false);
// Do return the contents of the call
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// Make the call
$xml = curl_exec($session);
// And close the session
curl_close($session);

// create a json object to traverse the results
$result = json_decode($xml);

This code sends the URL you constructed through your search form to the DPLA API. Rather than passing it in the browser navigation area, it uses curl, which has the effect of obfuscating your API Key. The results code also creates a variable, $result, which contains the JSON Linked Data response from the DPLA API, decoded for faster processing using a PHP function called json_decode.

Displaying Results

First, we want to know how many results there are. Immediately after the code you just inserted, add:

// get number of results
$count = 0;
$numresults = intval($result->count);
echo '<p>Your search for "'.$query.'" returned '.$numresults.' results.</p>';

This reads the response, looking for the count of objects found by the query. We have to create the variable $count, which is initially set to zero. Then we look for the count provided in the DPLA API reponse and insert it in the variable $numresults.

Save the file and try opening it in your web browser, using the localhost URL you identified above. Did you notice an error? Even before you enter a query, it displays the information:

Your search for "" returned 0 results. Results 1-10:

To correct this, we need to insert another IF clause, wrapping the entire results display. First, we want to make sure that no message at all is displayed before a query is submitted. Second, we want to consider the possibility that no results at all are returned, in which case we don’t want the message to say “Results 1-10:”. We will need to insert the first part of the IF-THEN-ELSE clause before the statement telling the user how many results were returned. Replace the lines

// get number of results
$count = 0;
$numresults = intval($result->count);
echo '<p>Your search for "'.$query.'" returned '.$numresults.' results. Results 1-10:</p>';

with

// get number of results
$numresults = intval($result->count);
$count = 0;

// if number of results are greater than zero, display number of results.
if ($numresults > 0) {
  echo '<p>Your search for "'.$query.'" returned '.$numresults.' results. Results 1-10:</p>';
  }

Reload the page in your web browser and test it again.

Next, we want to see what happens when a query produces no results. Try searching for “yrcsd“. If we were to look at the actual response returned by the DPLA API, it is:

{"count":0,"start":0,"limit":10,"docs":[],"facets":[]}

However, in our display there is no message at all. In order to let the user know, in our display, that their query produced no results, we should add an ELSE clause. Now change the IF clause you added above to include an ELSE:

// if number of results are greater than zero, display number of results.
if ($numresults > 0) {
  echo '<p>Your search for "'.$query.'" returned '.$numresults.' results. Results 1-10:</p>';
  } else {
  // no results case. If no results, return error message. 
  if (isset($cquery)) {
    echo '<p>Your search for "'.$query.'" returned no results. Please search again.</p>';
  } 
  }

Assuming that there are results to display, we need to decide how to show them. After the line

echo '<p>Your search for "'.$query.'" returned '.$numresults.' results. Results 1-10:</p>';

Insert a table to hold the results:

$count++;
if ($count <= 10) {
    $link = $doc->isShownAt;
    $title = $doc->sourceResource->title;
    // display item
    echo '<tr><td><a href="' . $link . '" target="_blank">' . $title . '</a></td></tr>';
 }
}
echo '</table>';

Here, the code inserts a table and begins processing the individual objects from the DPLA API response, using a foreach method that loops through the response. For each of the first 10 objects in the response, the code will extract the URL of the original item, wherever it might be online (in the response, isShownAt) and the title of the object (title, found in the section of the response labeled sourceResource). Each of these pieces of information will be stored in a separate variable. Note that because DPLA pulls information from many different “hubs,” the URL of the object will not be a DPLA address but will rather be the address of the hub that has the object in its asset management system.

Save your code and test it in your web browser, again using your localhost URL. You might notice a problem. A search for  “Texas” produces the following results:

Your search for "texas" returned 408697 results. Results 1-10:
Array
Array
Array
Array
Array
Texas
Texas
Texas
Texas
Array

Rather than giving us titles for objects, in some cases the display is telling us that there is an array, or more than one instance of the title response. A partial record in this DPLA API response looks like this:

"isShownAt":"http://texashistory.unt.edu/ark:/67531/metapth32913/",
"dataProvider":["Star of the Republic Museum"],
"provider":{
    "@id":"http://dp.la/api/contributor/the_portal_to_texas_history",
    "name":"The Portal to Texas History"},
"object":"http://texashistory.unt.edu/ark:/67531/metapth32913/thumbnail/",
"ingestionSequence":6,"id":"9bfa74d12bb99495be96ed9d013b85a7",
"_rev":"6-0caa1cbee959399ad0068789fe71842f",
"ingestDate":"2014-04-01T14:58:59.538274",
"_id":"texas--info:ark/67531/metapth32913",
"admin":{
     "sourceResource":{
          "title":"\"Texas\""}},
"sourceResource":{
    "rights":"... http://texashistory.unt.edu/terms-of-use/",
    "title":["\"Texas\""],
    "format":"Image",
....

There are two instances of title in this snippet of the response, each found in a section of the response labeled sourceResource. This reveals a challenge for working with DPLA metadata. The distributed nature of DPLA means that the metadata provided in a response is often inconsistent. In the case of title, the metadata for some hubs will include multiple instances of title and other fields, which our json_decode process interprets as arrays, while for other hubs the metadata will result in only a single value.

The easiest way to fix this is to tell our display code to use only the first instance of title in a sourceResource section of the response. Insert the following code after the line $title = $doc->sourceResource->title;

// If there is an array, use the first value
if (is_array($title)) {
$title = $title[0];
}

We haven’t yet looked to see if there is a thumbnail image for the object included in the response. Most, but not all, objects have thumbnails, but we need to address the case in which there is no image. The variable $image will hold either the URL of the thumbnail image or the URL of a placeholder, as used by DPLA itself.

// thumbnail object
if (isset($doc->object)) {
$image = $doc->object;
}

Now modify the code that displays the table to include the image, replacing the original code with this:

// display item
echo '<tr><td><a href="'.$link.'" target="_blank"><img src="' . $image . '" width="55" /></a></td><td><a href="' . $link . '" target="_blank">' . $title . '</a></td></tr>';

You may find that sometimes our code doesn’t find a thumbnail image. This is most common for books and other textual materials. If that happens, we want to use a placeholder image, instead. DPLA provides one at http://dp.la/assets/icon-text.gif, and we will use that. Add an ELSE statement to your thumbnail code. The final section should look like this:

// thumbnail object. If no thumbnail is set, use placeholder
if (isset($doc->object)) {
$image = $doc->object;
} else {
  $image = "http://dp.la/assets/icon-text.gif";
}

One more important piece of information to add to the display is the name of the institution that provided the object. This institution is listed in the DPLA API response as dataProvider. We need to tell the code to look for a dataProvider and assign the value to a variable. As we did for title, we will take the first value given in the response to avoid arrays.

Insert the following code after the end of the title block:

// institution that provided the object. If there is an array, use the first value 
$provider = $doc->dataProvider;
if (is_array($provider)) {
$provider = $provider[0];
}

Modify the display to include the name of the provider institution, adding a line break to keep the display tidy. We can’t link to the institution directly, because the DPLA API response doesn’t provide that information, so we just need to insert the $provider variable. Replace the original code for the display table with this:

// display item
echo '<tr><td><a href="'.$link.'" target="_blank"><img src="' . $image . '" width="55" /></a></td><td><a href="' . $link . '" target="_blank">' . $title . '</a><br />' . $provider . '</td></tr>';

There are a few more things we can do to improve this display. One is to address the issue of how to show the user additional results, if there are more than 10. We’ll cheat a little here; rather than providing a link for “next” or some other method to display the remaining results, we will simply provide a link that takes the user to the DPLA portal, with the search for the query pre-populated, much as we did in our original simple search example.

Insert this code directly after the line echo '</table>';

// provide link to jump out to DPLA search, including query
echo '<a href="http://dp.la/search?q='.$cquery.'" target="_blank">See full results for your query "'.$query.'" at the Digital Public Library of America</a>';

Testing the Code

Save and test your code. Testing is critical to successful coding. Try running as many different tests as you can think of to find problems. Use special characters in your query. Search for specific known items. At this point, you want to try to break your code so that users won’t discover issues later on.

Here’s an example of a minor issue that might come up. For some queries, there might be more than zero but fewer than 10 results. It doesn’t happen often (DPLA has more than 7 million items at the time I was developing this!), but it does happen. Try experimenting with searches, adding additional key words, to see if you can find an example of this.

In a case like this, we don’t want to tell the user that we’re showing them “results 1-10” when there are fewer than 10 results displayed. And we don’t want to send them to see more results at DPLA if there’s nothing more to show. We can fix this with two more IF-THEN-ELSE statements.

Change the line

echo '<p>Your search for "'.$query.'" returned '.$numresults.' results. Results 1-10:</p>';

To say

if ($numresults < 10) {
  echo '<p>Your search for "'.$query.'" returned '.$numresults.' results. Results 1-'.$numresults.':</p>';
} else {
  echo '<p>Your search for "'.$query.'" returned '.$numresults.' results. Results 1-10:</p>';
}

Because you’re already working within an IF statement, you need to be very careful with your curly braces here. Mismatched beginning and end braces will cause your code to break. When you test it, it might not provide an results at all, or it might display an error message.

We also need to make a change to the closing redirect out to DPLA search results. Replace the lines:

// provide link to jump out to DPLA search, including query
echo '<a href="http://dp.la/search?q='.$cquery.'" target="_blank">See full results for your query "'.$query.'" at the Digital Public Library of America</a>';

with

if ($numresults > 10) {
  // provide link to jump out to DPLA search, including query
  echo '<a href="http://dp.la/search?q='.$cquery.'" target="_blank">See full results for your query "'.$query.'" at the Digital Public Library of America</a>';
} else {
  echo 'Results provided by the <a href="http://dp.la" target="_blank">Digital Public Library of America</a>.';
}

The code should now return a simple “Results provided by” statement if there are fewer than 10 results. Because all of this is  wrapped within an IF statement that ensures that there are some results to work with, we should still get a different message when there are zero results. Test again to be sure.

The End

Congratulations! You’ve reached the end of the tutorial. There are other things that could be done with this search form. We could improve the CSS for our results, and we could add other information to the display. Look through the DPLA API response to see what else might be useful. Creator? Description? Subject? Location?

We could also modify the search form. The DPLA API allows searches on specific fields — for example, it is possible to search only the title field, or location, or creator, and so on. It would even be possible to create an Advanced Search form, which would appeal to librarians, if not to other users. But that, as they say, is a topic for another day, or at least for another tutorial.

If you want to check your work, a complete dpla-api-search.php example, as well as example dpla-simple-search.html and dpla-api-search.html pages and the text of this tutorial have been checked into GitHub at https://github.com/dcplumer/dpla-search-tutorial/. If you have any questions about this tutorial, please contact:

Danielle Cunniff Plumer
danielle@dcplumer.com

Leave a Reply