KEMBAR78
API Technical Writing | PDF
tcworld India 2016
API Technical Writing
#APItechcomm @sarahmaddox
Introduction to
contents
#APItechcomm @sarahmaddox
What is an API?
Our role and audience
API types
Demos of two APIs
Components of API documentation
Examples of API documentation
Working with an engineering team
How to get started
contents
#APItechcomm @sarahmaddox
What is an API?
Our role and audience
API types
Demos of two APIs
Components of API documentation
Examples of API documentation
Working with an engineering team
How to get started
#APItechcomm @sarahmaddox
What is an API?
#APItechcomm @sarahmaddox
Application Programming Interface (API)
A means of communication
● App to app
● Automated
A description of the communication methods allowed
● Requesting information
● Sending information
● Updating information
The mechanisms supporting those interactions
A way for apps to
exchange information
with each otherWhat is an API?
#APItechcomm @sarahmaddox
Usually not UI
○ Software-to-software interaction, not user interaction
○ May provide a UI widget
“Components” rather than “apps”?
○ Yes, that’s more precise
○ But “app” is good for most purposes
“APIs” = features within an API?
○ No, although fairly common usage
○ Those are classes, methods, endpoints, etc
A way for apps to
exchange information
with each otherWhat is an API?
#APItechcomm @sarahmaddox
The rules / protocol
● Documentation
● WSDL
● WADL
Code libraries
What an app needs
#APItechcomm @sarahmaddox
WWW
URI or URL
HTTP or HTTPS
Web service APIs
SOAP
XML-RPC and JSON-RPC
REST
Web services
REST APIs
and more
#APItechcomm @sarahmaddox
#APItechcomm @sarahmaddox
WSDL
WADL
Docs
#APItechcomm @sarahmaddox
http://www.greycloudapp.com/connection/xml?type=hello
#APItechcomm @sarahmaddox
<?xml version="1.0"
encoding="utf-8" ?>
<GreyCloudAppResponse>
<status>OK</status>
<result>
<type>greeting</type>
<text>hello back</text>
</result>
</GreyCloudAppResponse>
#APItechcomm @sarahmaddox
The role of an API tech writer
#APItechcomm @sarahmaddox
Explain concepts
Show people how to do something
Publish the terms of service of a product
Notify people of changes and new features
What does an API technical writer do?
Help people complete a task
or use a product
#APItechcomm @sarahmaddox
What does an API technical writer do?
Advise developers on naming conventions
Stand up for code readability
Write sample code
Write video scripts
Present videos, workshops, webinars
<
else
Opportunities for creativity
as well as writing/coding zone
#APItechcomm @sarahmaddox
<script type=‘text/javascript’>
// Say hello world until the user starts questioning
// the meaningfulness of their existence.
function helloWorld(world) {
for (var i = 42; i > 0; i--) {
alert (‘Hello’ + String(world));
}
}
</script>
You mean you spend your day on stuff like this?
#APItechcomm @sarahmaddox
<script type=‘text/javascript’>
// Say hello world until the user starts questioning
// the meaningfulness of their existence.
function helloWorld(world) {
for (var i = 42; i > 0; i--) {
alert (‘Hello’ + String(world));
}
}
</script>
You mean you spend your day on stuff like this?
;-)
#APItechcomm @sarahmaddox
Who’s our audience?
#APItechcomm @sarahmaddox
Inventive
Innovative
Entrepreneurial
Web apps
iOS
Android
Desktop
Wearable
youNameIt
Developers.
They’re our audience.
Who uses APIs?
#APItechcomm @sarahmaddox
● Display your Twitter stream on your Wordpress blog
● Add Flickr photos to Confluence wiki pages
● Embed YouTube videos all over the show
APIs in the real world
#APItechcomm @sarahmaddox
API types
#APItechcomm @sarahmaddox
Web service APIs
SOAP
XML-RPC and JSON-RPC
REST
Library-based APIs
JavaScript
TWAIN
Class-based APIs (object orientation)
Java API
Android API
OS functions and routines
Access to file system
Access to user interface
Object remoting APIs
CORBA
.NET Remoting
Hardware APIs
Video accelerators
Cameras
A classification of APIs
#APItechcomm @sarahmaddox
http://goo.gl/tTqyne
Long link:
http://ffeathers.wordpress.com/2014/02/16/api-types
More details of API types
#APItechcomm @sarahmaddox
Demo of a JavaScript API
#APItechcomm @sarahmaddox
Google Maps
JavaScript API
#APItechcomm @sarahmaddox
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
html, body { height: 100%; margin: 0; padding: 0; }
#map { height: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -33.857, lng: 151.215},
zoom: 13
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=YOUR-API-KEY&callback=initMap">
</script>
</body>
</html>
Google Maps
JavaScript API
#APItechcomm @sarahmaddox
<head>
<style type="text/css">
html, body {
height: 100%;
margin: 0;
padding: 0; }
#map { height: 100%; }
</style>
</head>
Google Maps
JavaScript API
#APItechcomm @sarahmaddox
<body>
<div id="map"></div>
…
</body>
Google Maps
JavaScript API
#APItechcomm @sarahmaddox
<script async defer
src="https://maps.googleapis.com/maps/api/js
?key=YOUR-KEY-HERE
&callback=initMap">
</script>
Google Maps
JavaScript API
#APItechcomm @sarahmaddox
<script type="text/javascript">
var map;
function initMap() {
map = new google.maps
.Map(document.getElementById('map'),
{center: {lat: -33.857,
lng: 151.215},
zoom: 13
});
}
</script>
Google Maps
JavaScript API
#APItechcomm @sarahmaddox
Google Maps
JavaScript API
#APItechcomm @sarahmaddox
Google Maps
JavaScript API
#APItechcomm @sarahmaddox
Demo of a REST API
#APItechcomm @sarahmaddox
WWW
URI or URL
HTTP or HTTPS
Web service APIs
SOAP
XML-RPC and JSON-RPC
REST
Web services
REST APIs
and more
#APItechcomm @sarahmaddox
Calling the Flickr API
<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<photos page="1" pages="7" perpage="100" total="606">
<photo id=8554933095" owner="31065906@N08" secret="211xxxxxxx" server="8380"
farm="9" title="IMG_4536" ispublic="1" isfriend="0" isfamily="0" />
<photo id="8556044604" owner="31065906@N08" secret="b7bxxxxxxx" server="8368"
farm="9" title="IMG_4533" ispublic="1" isfriend="0" isfamily="0" />
<photo id="8556045230" owner="31065906@N08" secret="847xxxxxxx" server="8505"
farm="9" title="IMG_4529" ispublic="1" isfriend="0" isfamily="0" />
<photo id="8554934541" owner="31065906@N08" secret="9b38xxxxxx" server="8112"
farm="9" title="IMG_4527" ispublic="1" isfriend="0" isfamily="0" />
Get a list:
● Request
● Response
Get a photo:
● Request
● Response
#APItechcomm @sarahmaddox
http://www.flickr.com/photos/31065906@N08/12376039474
#APItechcomm @sarahmaddox
https://api.flickr.com/services/rest/?
Flickr API request
#APItechcomm @sarahmaddox
https://api.flickr.com/services/rest/?
&method=flickr.people.getPublicPhotos
Flickr API request
#APItechcomm @sarahmaddox
https://api.flickr.com/services/rest/?
&method=flickr.people.getPublicPhotos
&user_id=31065906@N08
Flickr API request
#APItechcomm @sarahmaddox
https://api.flickr.com/services/rest/?
&method=flickr.people.getPublicPhotos
&user_id=31065906@N08
&api_key=KEY-GOES-HERE
Flickr API request
http://www.flickr.com/services/api/keys/apply/
#APItechcomm @sarahmaddox
A Chrome add-onAdvanced REST Client
Testing web services and REST APIs
#APItechcomm @sarahmaddox
<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<photos page="1" pages="7" perpage="100" total="606">
<photo id="8554933095" owner="31065906@N08" secret="211xxxxxxx" server="8380" farm="9"
title="IMG_4536" ispublic="1" isfriend="0" isfamily="0" />
<photo id="8556044604" owner="31065906@N08" secret="b7bxxxxxxx" server="8368" farm="9"
title="IMG_4533" ispublic="1" isfriend="0" isfamily="0" />
<photo id="8556045230" owner="31065906@N08" secret="847xxxxxxx" server="8505" farm="9"
title="IMG_4529" ispublic="1" isfriend="0" isfamily="0" />
<photo id="8554934541" owner="31065906@N08" secret="9b38xxxxxx" server="8112" farm="9"
title="IMG_4527" ispublic="1" isfriend="0" isfamily="0" />
Calling the Flickr API
#APItechcomm @sarahmaddox
http://www.flickr.com/photos/31065906@N08/12376039474
#APItechcomm @sarahmaddox
HTTP protocol - what we’ve ignored
<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<photos page="1" pages="7" perpage="100" total="606">
<photo id=8554933095" owner="31065906@N08" secret="211xxxxxxx" server="8380"
farm="9" title="IMG_4536" ispublic="1" isfriend="0" isfamily="0" />
<photo id="8556044604" owner="31065906@N08" secret="b7bxxxxxxx" server="8368"
farm="9" title="IMG_4533" ispublic="1" isfriend="0" isfamily="0" />
<photo id="8556045230" owner="31065906@N08" secret="847xxxxxxx" server="8505"
farm="9" title="IMG_4529" ispublic="1" isfriend="0" isfamily="0" />
<photo id="8554934541" owner="31065906@N08" secret="9b38xxxxxx" server="8112"
farm="9" title="IMG_4527" ispublic="1" isfriend="0" isfamily="0" />
Types of requests:
● GET
● POST, PUT, DELETE, more
Request/response:
● Header and body
● Status
● Data types
#APItechcomm @sarahmaddox
Components of API documentation
#APItechcomm @sarahmaddox
What’s in API docs
Conceptual
Overviews
Concepts
Use cases
Practical
Quick start
Tutorials
Sample code
Reference documentation
Hand-written
Auto-generated (Javadoc and others)
Advantage of auto-generation
Disadvantage of auto-generation
#APItechcomm @sarahmaddox
/**
* Short description here.
* More description.
* Can contain links to other parts of the doc: {@link NAME}.
* Can contain <strong>HTML tags</strong>.
* Ends with special "block tags" denoting specific sections of the page.
*
* @param argument1 description of a parameter
* @param argument2 description of a parameter
* @return description of what the method returns
*/
Generated docs - Javadoc comments
#APItechcomm @sarahmaddox
/**
* Prints the user’s favourite toy.
* The printed string includes some predefined text and the
* <strong>color</strong> and <strong>type</strong> of the toy.
*
* @param color A string containing the color of the toy.
* @param toy A string containing the type of toy.
*/
private void printToy(String color, String toy) {
String s = String.format("My favorite toys are %s %s.", color, toy);
System.out.println(s);
}
Example of a Javadoc comment
#APItechcomm @sarahmaddox
Examples of API documentation
#APItechcomm @sarahmaddox
Example documentation for a JavaScript API
Google Maps JavaScript API
Getting started: http://goo.gl/uc8nL
How-to guides for common use cases: http://goo.gl/IDmSPg
Reference: http://goo.gl/W2yaZ
#APItechcomm @sarahmaddox
Example documentation for a REST API
Twitter REST API
Overview and getting started: http://goo.gl/QVRN8y
How-to guides for common use cases: http://goo.gl/B46St5
Reference: http://goo.gl/ie0gpE
#APItechcomm @sarahmaddox
Example documentation for a Java-based API
Google Maps Android API
Overview: http://goo.gl/pPAMq
Getting started: http://goo.gl/fgdUM
How-to guides for common use cases: http://goo.gl/JlVOcQ
Reference: http://goo.gl/ky1ijm
#APItechcomm @sarahmaddox
Working with an engineering team
#APItechcomm @sarahmaddox
Sit with the team
Grok teamwork
Be the advocate for your audience - those “other” developers
Get to know the tools
Gather and share information
A day in the life
#APItechcomm @sarahmaddox
What about code?
Code
http://goo.gl/JII3O0
http://ffeathers.wordpress.com/
2013/12/21/how-to-write-sample-code
#APItechcomm @sarahmaddox
Getting started
Code
#APItechcomm @sarahmaddox
How to get started
Get the tech
Show the ‘tude
Play with some APIs
Do some docs
Follow Hacker News
Follow up on this presentation
https://news.ycombinator.com
MDN and WebPlatform.org
#APItechcomm @sarahmaddox
What is an API?
Our role and audience
API types
Demos of two APIs
Components of API documentation
Examples of API documentation
Working with an engineering team
How to get started
#APItechcomm @sarahmaddox
Why an API tech writer?
APIs are the communication channel of the connected world.
API developers need help hooking their app up to someone else’s API.
Tech writers who can give that help are in a very good position.
#APItechcomm @sarahmaddox
“There is no line where you suddenly cross over
from non-coder to coder, or from fake developer
to real developer. There’s no high priesthood.
You start learning,
and then you just keep going.”
Noah Veltman
Code, the newsroom, and self-doubt
#APItechcomm @sarahmaddox
Twitter @sarahmaddox
Google+ +sarahmaddox
Slideshare sarahmaddox
Blog ffeathers.wordpress.com
Contacting me

API Technical Writing