Turn your DOI into more metadata!
with HTTP content negotiation in your toolbox
( slides: http://z.umn.edu/c4ldoi )
Content negotiation crash course
Provide an Accept: HTTP request header to ask for an XML, JSON, or citation format;
Listing desired content types comma-separated
Accept: application/citeproc+json;q=1.0, application/unixref+xml;q=0.5
I'd be happy with either JSON or an XML document...
http://z.umn.edu/c4ldoi
Content negotiation crash course
Provide an Accept: HTTP request header to ask for an XML, JSON, or citation format;
Listing desired content types comma-separated
Accept: application/citeproc+json;q=1.0, application/unixref+xml;q=0.5
…But would prefer JSON if you have it.
http://z.umn.edu/c4ldoi
Issue your GET to dx.doi.org
Command line curl example:
$ curl -L -H 'Accept: application/citeproc+json, application/unixref+xml' \
'http://dx.doi.org/10.1038/nphys3689'
* Connected to dx.doi.org (63.123.152.248) port 80 (#0)
> GET /10.1038/nphys3689 HTTP/1.1
> User-Agent: curl/7.35.0
> Host: dx.doi.org
> Accept: application/citeproc+json, application/unixref+xml
< HTTP/1.1 303 See Other
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< Vary: Accept
< Location: http://data.crossref.org/10.1038%2Fnphys3689
http://z.umn.edu/c4ldoi
Don't forget to follow Location:
Command line curl example:
$ curl -L -H 'Accept: application/citeproc+json, application/unixref+xml' \
'http://dx.doi.org/10.1038/nphys3689'
* Connected to dx.doi.org (63.123.152.248) port 80 (#0)
> GET /10.1038/nphys3689 HTTP/1.1
> User-Agent: curl/7.35.0
> Host: dx.doi.org
> Accept: application/citeproc+json
< HTTP/1.1 303 See Other
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< Vary: Accept
< Location: http://data.crossref.org/10.1038%2Fnphys3689
http://z.umn.edu/c4ldoi
Check the Content-Type: returned
Command line curl example:
$ curl -L -H 'Accept: application/citeproc+json, application/unixref+xml' \
'http://dx.doi.org/10.1038/nphys3689'
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: X-Requested-With, Accept, Accept-Encoding, Accept-Charset, Accept-Language, Accept-Ranges, Cache-Control
< Access-Control-Expose-Headers: Link
< Link: <http://dx.doi.org/10.1038/nphys3689>; rel="canonical"
< Content-Type: application/citeproc+json
< Content-Length: 976
< Server: http-kit
< Date: Wed, 09 Mar 2016 03:12:32 GMT
http://z.umn.edu/c4ldoi
And get some JSON
{
"indexed": {
"date-parts": [
[2016, 3, 4]
],
},
...SNIP...
"page": "203-203",
"source": "CrossRef",
"title": "New Horizons: Small but still special",
"volume": "12",
"alternative-id": ["nphys3689"],
"URL": "http:\/\/dx.doi.org\/10.1038\/nphys3689",
"ISSN": ["1745-2473", "1745-2481"],
"subject": ["Physics and Astronomy(all)"]
}
http://z.umn.edu/c4ldoi
Or maybe some XML
<?xml version="1.0" encoding="UTF-8"?>
<doi_records>
<doi_record owner="10.1038" timestamp="2016-03-01 04:21:30">
<crossref>
<journal>
<journal_metadata>
<full_title>Nature Physics</full_title>
<abbrev_title>Nat Phys</abbrev_title>
<issn media_type="print">1745-2473</issn>
<issn media_type="electronic">1745-2481</issn>
</journal_metadata>
<journal_issue>
...SNIP now our XML's invalid...
</journal_issue>
http://z.umn.edu/c4ldoi
Or a citation...
Chiao, M. (2016). New Horizons: Small but still special.
Nature Physics, 12(3), 203–203. doi:10.1038/nphys3689
http://z.umn.edu/c4ldoi
Doing that with Ruby
require 'simple_doi'
# Retrieve JSON metadata (default format)�doi = SimpleDOI::DOI.new('10.1038/nphys3689')��# Call .lookup (defaults to JSON)
json = doi.lookup�puts doi.response_content_type�# "application/vnd.citationstyles.csl+json"�
http://z.umn.edu/c4ldoi
Resources
UMN's SimpleDOI Ruby library to handle lookup and basic parsing of a few return formats (PHP coming soon too)
https://github.com/UMNLibraries/simpledoi-ruby
DOI Handbook section on content negotiation
https://www.doi.org/doi_handbook/5_Applications.html#5.4.1
CrossRef & DataCite documentation (supported formats list!)
http://z.umn.edu/c4ldoi
Michael Berkowski
mjb@umn.edu
@mberkowski
#code4lib IRC,
Twitter,
Slack
University of Minnesota Libraries
The University of Minnesota is an equal opportunity educator and employer.