SlideShare a Scribd company logo
1 of 24
Download to read offline
APIDOCInline Documentation for RESTful web APIs
Introduction with a small example.
http://apidocjs.com
What does apiDoc ?
apiDoc
… creates a Documentation HTML-Page
… use API-Descriptions from your source code
For who ?
apiDoc can be used with any programming language, that allow
block documentation:
/**
* This is a comment.
*/
Where i find apiDoc ?
apiDoc is Open Source and distributed over NPM and github
Visit: http://apidocjs.com
Special functions
apiDoc
… support own created Templates
… includes History
… compare old and new API-Method Versions
… allows frontend Developer to see what changed
… support Inherit
… reuse of Documentation parts
… extendable
… you can create your own Documentation Methods
Ok, let us begin...
apiDoc is a node module, so install Node.js first:
http://nodejs.org
Node.js includes „npm“, a package manager for node.
Install apiDoc
[sudo] npm install -g apidoc
We install apiDoc global, so you can access it from everywhere.
EXAMPLE PROJECT
We use a simple static JavaScript example.
We ignore routing, validation or database operations.
This are only small parts of apiDocs functions, for all visit http://apidocjs.com
There is also a complex example: http://apidocjs.com/#example-full
Create a new directory „my_project“.
Within that dir create a file „example.js“.
example.js
var currentUser = {
name: 'Mary'
};
function getUser() {
return { code: 200, data: currentUser };
}
function setName(name) {
if(name.length === 0) {
return { code: 404, message: 'NameEmptyError' };
}
currentUser.name = name;
return { code: 204 };
}
A basic doc
Above „function getUser“ we place a basic documentation block
/**
* @api {get} /user Request User information
* @apiName GetUser
* @apiGroup User
*/
function getUser() {
return { code: 200, data: currentUser };
}
This 3 parameters are required!
@api describes the path of the Method that clients call.
@apiName is a unique Name, you can name as you want, for simplicity i prefer
„Type of Method“ + „Name of Method“ e.g. {get} and „/user“ => GetUser.
@apiGroup is the name of the group to which this method belongs. The group will be
used for Navigation.
By default apiDoc search for all „.jjs“ files in current directory and sub directories.
You can change the includeFilter, call „apidoc -h“ for details.
apiDoc created a new HTML-Page in directory „doc“.
From command line run within „my_project“ directory:
apidoc
Open „doc/index.html“ in your Browser
We see the rudimentary Webpage, with Navigation left and Content right.
We have a group „User“ and within that group an API-Method „GET /user“
Describe the API-Answer
Now we add success return parameters
/**
* @api {get} /user Request User information
* @apiName GetUser
* @apiGroup User
*
* @apiSuccess {String} name The users name.
*/
function getUser() {
return { code: 200, data: currentUser };
}
apidoc
Run apiDoc again, it will overwrite the „doc“ Directory
Now we have a little more Information and see what „GET /user“ returns on a
successful reply „Success 200“.
Add a Version and example Code
We add a Version (Format “major.minor.patch”, see http://semver.org for details)
and we add an example code, that shows what will be return in case of success
/**
* @api {get} /user Request User information
* @apiName GetUser
* @apiGroup User
* @apiVersion 0.1.0
*
* @apiSuccess {String} name The users name.
*
* @apiSuccessExample Example data on success:
* {
* name: 'Paul'
* }
*/
function getUser() {
return { code: 200, data: currentUser };
}
In the right dropdown box we see now the Version „0.1.0“ and under „Success 200“
our integrated example.
VERSIONING
If you work in a Team and some Programmer work an the API backend and some on
Frontend Client, it is important to know what changed in a new Release.
Especially during developing an Application, many things can change.
An API Method change
Create a new file „_apidoc.js“.
Put only the documentation Block from „getUser“ in that file:
_apidoc.js
/**
* @api {get} /user Request User information
* @apiName GetUser
* @apiGroup User
* @apiVersion 0.1.0
*
* @apiSuccess {String} name The users name.
*
* @apiSuccessExample Example data on success:
* {
* name: 'Paul'
* }
*/
„_apidoc.js“ will be our history file and contains old documentation blocks.
Now we change the documentation block in „example.js“
example.js
/**
* @api {get} /user Request User information
* @apiName GetUser
* @apiGroup User
* @apiVersion 0.2.0
*
* @apiSuccess {String} name The users name.
* @apiSuccess {Number} age Calculated age from Birthday
*
* @apiSuccessExample Example data on success:
* {
* name: 'Paul',
* age: 27
* }
*/
function getUser() {
return { code: 200, data: currentUser };
}
After call „apidoc“ and open „doc/index.html“ you see now Version „0.2.0“ with the
Field „age“ and the changed example.
And now the magic...
Select from Dropdown „0.2.0“ the Version „0.1.0“.
You see now a comparison from the 2 Versions. Green marked content indicates the
Fields that are added to Version „0.2.0“.
In the future, when you made more changes to an API-Method, simply copy and add
the complete documentation block to the history file „_apidoc.js“.
Leave the old blocks as they are.
Then you have a Documentation where everybody can see any change of your API.
PARAMS AND ERRORS
We take now a quick look at how to add Parameters, that an API-Method need and
how we return errors.
We add now a documentation to our second function „setName“.
example.js
/**
* @api {put} /user Change User
* @apiName PutUser
* @apiGroup User
* @apiVersion 0.1.0
*
* @apiParam {String} name New name of the user
*
* @apiError NameEmptyError The name was empty. Minimum of <code>1</code> character is required.
*/
function setName(name) {
if(name.length === 0) {
return { code: 404, message: 'NameEmptyError' };
}
currentUser.name = name;
return { code: 204 };
}
You will see now the new „Change User“ entry in navigation and the content for the
API-Method.
Thank you and have a productive use !
For more Information visit http://apidocjs.com
Author: Peter Rottmann
peter@apidocjs.com

More Related Content

What's hot

API designing with WSO2 API Manager
API designing with WSO2 API ManagerAPI designing with WSO2 API Manager
API designing with WSO2 API ManagerWSO2
 
apidays LIVE New York 2021 - API tool chain for low budget programs by Paul K...
apidays LIVE New York 2021 - API tool chain for low budget programs by Paul K...apidays LIVE New York 2021 - API tool chain for low budget programs by Paul K...
apidays LIVE New York 2021 - API tool chain for low budget programs by Paul K...apidays
 
Buck outside Valley
Buck outside ValleyBuck outside Valley
Buck outside ValleyBruno Rocha
 
An Introduction to the WSO2 API Manager
An Introduction to the WSO2 API Manager An Introduction to the WSO2 API Manager
An Introduction to the WSO2 API Manager WSO2
 
Customizing workflows in WSO2 API Manager
Customizing workflows in WSO2 API ManagerCustomizing workflows in WSO2 API Manager
Customizing workflows in WSO2 API ManagerWSO2
 
Pure APIs: Development workflows for successful API integrations
Pure APIs: Development workflows for successful API integrationsPure APIs: Development workflows for successful API integrations
Pure APIs: Development workflows for successful API integrationsJosé Haro Peralta
 
Alm Specialist Toolkit Team System 2008 Deep Dive
Alm Specialist Toolkit   Team System 2008 Deep DiveAlm Specialist Toolkit   Team System 2008 Deep Dive
Alm Specialist Toolkit Team System 2008 Deep DiveChristian Thilmany
 
Design Driven API Development
Design Driven API DevelopmentDesign Driven API Development
Design Driven API DevelopmentSokichi Fujita
 
API workshop by AWS and 3scale
API workshop by AWS and 3scaleAPI workshop by AWS and 3scale
API workshop by AWS and 3scale3scale
 
OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)
OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)
OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)Open API Initiative (OAI)
 
Customizing the API Store & Publisher in WSO2 API Manager
Customizing the API Store & Publisher in WSO2 API ManagerCustomizing the API Store & Publisher in WSO2 API Manager
Customizing the API Store & Publisher in WSO2 API ManagerWSO2
 
Running the-next-generation-of-cloud-native-applications-using-open-applicati...
Running the-next-generation-of-cloud-native-applications-using-open-applicati...Running the-next-generation-of-cloud-native-applications-using-open-applicati...
Running the-next-generation-of-cloud-native-applications-using-open-applicati...NaveedAhmad239
 
Cloud-first SharePoint JavaScript Add-ins - Collab 365
Cloud-first SharePoint JavaScript Add-ins - Collab 365Cloud-first SharePoint JavaScript Add-ins - Collab 365
Cloud-first SharePoint JavaScript Add-ins - Collab 365Sonja Madsen
 
Build and Manage Serverless APIs (APIDays Nordic, May 19th 2016)
Build and Manage Serverless APIs (APIDays Nordic, May 19th 2016)Build and Manage Serverless APIs (APIDays Nordic, May 19th 2016)
Build and Manage Serverless APIs (APIDays Nordic, May 19th 2016)3scale
 
Global Azure BootCamp: Azure Logic Apps
Global Azure BootCamp: Azure Logic AppsGlobal Azure BootCamp: Azure Logic Apps
Global Azure BootCamp: Azure Logic AppsDavid Schneider
 
WSO2 API Manager : Going beyond the just API Management
WSO2 API Manager : Going beyond the just API ManagementWSO2 API Manager : Going beyond the just API Management
WSO2 API Manager : Going beyond the just API ManagementEdgar Silva
 
[API the Docs Paris 2018] Architecting DX
[API the Docs Paris 2018] Architecting DX[API the Docs Paris 2018] Architecting DX
[API the Docs Paris 2018] Architecting DXKathleen De Roo
 

What's hot (20)

API designing with WSO2 API Manager
API designing with WSO2 API ManagerAPI designing with WSO2 API Manager
API designing with WSO2 API Manager
 
Hccjp kong 210409
Hccjp kong 210409Hccjp kong 210409
Hccjp kong 210409
 
apidays LIVE New York 2021 - API tool chain for low budget programs by Paul K...
apidays LIVE New York 2021 - API tool chain for low budget programs by Paul K...apidays LIVE New York 2021 - API tool chain for low budget programs by Paul K...
apidays LIVE New York 2021 - API tool chain for low budget programs by Paul K...
 
Buck outside Valley
Buck outside ValleyBuck outside Valley
Buck outside Valley
 
Google Cloud Enpoints
Google Cloud EnpointsGoogle Cloud Enpoints
Google Cloud Enpoints
 
2.3.anypoint exchange
2.3.anypoint exchange2.3.anypoint exchange
2.3.anypoint exchange
 
An Introduction to the WSO2 API Manager
An Introduction to the WSO2 API Manager An Introduction to the WSO2 API Manager
An Introduction to the WSO2 API Manager
 
Customizing workflows in WSO2 API Manager
Customizing workflows in WSO2 API ManagerCustomizing workflows in WSO2 API Manager
Customizing workflows in WSO2 API Manager
 
Pure APIs: Development workflows for successful API integrations
Pure APIs: Development workflows for successful API integrationsPure APIs: Development workflows for successful API integrations
Pure APIs: Development workflows for successful API integrations
 
Alm Specialist Toolkit Team System 2008 Deep Dive
Alm Specialist Toolkit   Team System 2008 Deep DiveAlm Specialist Toolkit   Team System 2008 Deep Dive
Alm Specialist Toolkit Team System 2008 Deep Dive
 
Design Driven API Development
Design Driven API DevelopmentDesign Driven API Development
Design Driven API Development
 
API workshop by AWS and 3scale
API workshop by AWS and 3scaleAPI workshop by AWS and 3scale
API workshop by AWS and 3scale
 
OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)
OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)
OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)
 
Customizing the API Store & Publisher in WSO2 API Manager
Customizing the API Store & Publisher in WSO2 API ManagerCustomizing the API Store & Publisher in WSO2 API Manager
Customizing the API Store & Publisher in WSO2 API Manager
 
Running the-next-generation-of-cloud-native-applications-using-open-applicati...
Running the-next-generation-of-cloud-native-applications-using-open-applicati...Running the-next-generation-of-cloud-native-applications-using-open-applicati...
Running the-next-generation-of-cloud-native-applications-using-open-applicati...
 
Cloud-first SharePoint JavaScript Add-ins - Collab 365
Cloud-first SharePoint JavaScript Add-ins - Collab 365Cloud-first SharePoint JavaScript Add-ins - Collab 365
Cloud-first SharePoint JavaScript Add-ins - Collab 365
 
Build and Manage Serverless APIs (APIDays Nordic, May 19th 2016)
Build and Manage Serverless APIs (APIDays Nordic, May 19th 2016)Build and Manage Serverless APIs (APIDays Nordic, May 19th 2016)
Build and Manage Serverless APIs (APIDays Nordic, May 19th 2016)
 
Global Azure BootCamp: Azure Logic Apps
Global Azure BootCamp: Azure Logic AppsGlobal Azure BootCamp: Azure Logic Apps
Global Azure BootCamp: Azure Logic Apps
 
WSO2 API Manager : Going beyond the just API Management
WSO2 API Manager : Going beyond the just API ManagementWSO2 API Manager : Going beyond the just API Management
WSO2 API Manager : Going beyond the just API Management
 
[API the Docs Paris 2018] Architecting DX
[API the Docs Paris 2018] Architecting DX[API the Docs Paris 2018] Architecting DX
[API the Docs Paris 2018] Architecting DX
 

Viewers also liked

(API) Docs for Developers
(API) Docs for Developers(API) Docs for Developers
(API) Docs for DevelopersBrandon West
 
Learnings @WalmartLabs - Agile journey
Learnings @WalmartLabs  - Agile journeyLearnings @WalmartLabs  - Agile journey
Learnings @WalmartLabs - Agile journeyAbinav Munshi
 
Distribution, redundancy and high availability using OpenSIPS
Distribution, redundancy and high availability using OpenSIPSDistribution, redundancy and high availability using OpenSIPS
Distribution, redundancy and high availability using OpenSIPSDigium
 
AWS October Webinar Series - Introducing Amazon Elasticsearch Service
AWS October Webinar Series - Introducing Amazon Elasticsearch ServiceAWS October Webinar Series - Introducing Amazon Elasticsearch Service
AWS October Webinar Series - Introducing Amazon Elasticsearch ServiceAmazon Web Services
 
2015 Future of Open Source Survey Results
2015 Future of Open Source Survey Results2015 Future of Open Source Survey Results
2015 Future of Open Source Survey ResultsBlack Duck by Synopsys
 
OPEN SOURCE SEMINAR PRESENTATION
OPEN SOURCE SEMINAR PRESENTATIONOPEN SOURCE SEMINAR PRESENTATION
OPEN SOURCE SEMINAR PRESENTATIONRitwick Halder
 
(BDT209) Launch: Amazon Elasticsearch For Real-Time Data Analytics
(BDT209) Launch: Amazon Elasticsearch For Real-Time Data Analytics(BDT209) Launch: Amazon Elasticsearch For Real-Time Data Analytics
(BDT209) Launch: Amazon Elasticsearch For Real-Time Data AnalyticsAmazon Web Services
 
Open Source Creativity
Open Source CreativityOpen Source Creativity
Open Source CreativitySara Cannon
 

Viewers also liked (8)

(API) Docs for Developers
(API) Docs for Developers(API) Docs for Developers
(API) Docs for Developers
 
Learnings @WalmartLabs - Agile journey
Learnings @WalmartLabs  - Agile journeyLearnings @WalmartLabs  - Agile journey
Learnings @WalmartLabs - Agile journey
 
Distribution, redundancy and high availability using OpenSIPS
Distribution, redundancy and high availability using OpenSIPSDistribution, redundancy and high availability using OpenSIPS
Distribution, redundancy and high availability using OpenSIPS
 
AWS October Webinar Series - Introducing Amazon Elasticsearch Service
AWS October Webinar Series - Introducing Amazon Elasticsearch ServiceAWS October Webinar Series - Introducing Amazon Elasticsearch Service
AWS October Webinar Series - Introducing Amazon Elasticsearch Service
 
2015 Future of Open Source Survey Results
2015 Future of Open Source Survey Results2015 Future of Open Source Survey Results
2015 Future of Open Source Survey Results
 
OPEN SOURCE SEMINAR PRESENTATION
OPEN SOURCE SEMINAR PRESENTATIONOPEN SOURCE SEMINAR PRESENTATION
OPEN SOURCE SEMINAR PRESENTATION
 
(BDT209) Launch: Amazon Elasticsearch For Real-Time Data Analytics
(BDT209) Launch: Amazon Elasticsearch For Real-Time Data Analytics(BDT209) Launch: Amazon Elasticsearch For Real-Time Data Analytics
(BDT209) Launch: Amazon Elasticsearch For Real-Time Data Analytics
 
Open Source Creativity
Open Source CreativityOpen Source Creativity
Open Source Creativity
 

Similar to apiDoc Introduction

Creating web api and consuming- part 1
Creating web api and consuming- part 1Creating web api and consuming- part 1
Creating web api and consuming- part 1Dipendra Shekhawat
 
Google Cloud Endpoints - Soft Uni 19.06.2014
Google Cloud Endpoints - Soft Uni 19.06.2014Google Cloud Endpoints - Soft Uni 19.06.2014
Google Cloud Endpoints - Soft Uni 19.06.2014Dimitar Danailov
 
OpenSocial Intro
OpenSocial IntroOpenSocial Intro
OpenSocial IntroPamela Fox
 
Django 1.10.3 Getting started
Django 1.10.3 Getting startedDjango 1.10.3 Getting started
Django 1.10.3 Getting startedMoniaJ
 
SFScon 2020 - Nikola Milisavljevic - BASE - Python REST API framework
SFScon 2020 - Nikola Milisavljevic - BASE - Python REST API frameworkSFScon 2020 - Nikola Milisavljevic - BASE - Python REST API framework
SFScon 2020 - Nikola Milisavljevic - BASE - Python REST API frameworkSouth Tyrol Free Software Conference
 
How to build crud application using vue js, graphql, and hasura
How to build crud application using vue js, graphql, and hasuraHow to build crud application using vue js, graphql, and hasura
How to build crud application using vue js, graphql, and hasuraKaty Slemon
 
-Kotlin_Camp_Unit2.pptx
-Kotlin_Camp_Unit2.pptx-Kotlin_Camp_Unit2.pptx
-Kotlin_Camp_Unit2.pptxRishiGandhi19
 
Android application architecture
Android application architectureAndroid application architecture
Android application architectureRomain Rochegude
 
Appcelerator Titanium Alloy + Kinvey Collection Databinding - Part One
Appcelerator Titanium Alloy + Kinvey Collection Databinding - Part OneAppcelerator Titanium Alloy + Kinvey Collection Databinding - Part One
Appcelerator Titanium Alloy + Kinvey Collection Databinding - Part OneAaron Saunders
 
Schema-First API Design
Schema-First API DesignSchema-First API Design
Schema-First API DesignYos Riady
 
Cloud native programming model comparison
Cloud native programming model comparisonCloud native programming model comparison
Cloud native programming model comparisonEmily Jiang
 
Angularjs2 presentation
Angularjs2 presentationAngularjs2 presentation
Angularjs2 presentationdharisk
 
iOS Swift application architecture
iOS Swift application architectureiOS Swift application architecture
iOS Swift application architectureRomain Rochegude
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLAkhil Mittal
 
Basic iOS Training with SWIFT - Part 4
Basic iOS Training with SWIFT - Part 4Basic iOS Training with SWIFT - Part 4
Basic iOS Training with SWIFT - Part 4Manoj Ellappan
 

Similar to apiDoc Introduction (20)

Creating web api and consuming- part 1
Creating web api and consuming- part 1Creating web api and consuming- part 1
Creating web api and consuming- part 1
 
Google cloud endpoints
Google cloud endpointsGoogle cloud endpoints
Google cloud endpoints
 
Google Cloud Endpoints - Soft Uni 19.06.2014
Google Cloud Endpoints - Soft Uni 19.06.2014Google Cloud Endpoints - Soft Uni 19.06.2014
Google Cloud Endpoints - Soft Uni 19.06.2014
 
OpenSocial Intro
OpenSocial IntroOpenSocial Intro
OpenSocial Intro
 
Introduction to Hydra
Introduction to HydraIntroduction to Hydra
Introduction to Hydra
 
Django 1.10.3 Getting started
Django 1.10.3 Getting startedDjango 1.10.3 Getting started
Django 1.10.3 Getting started
 
SFScon 2020 - Nikola Milisavljevic - BASE - Python REST API framework
SFScon 2020 - Nikola Milisavljevic - BASE - Python REST API frameworkSFScon 2020 - Nikola Milisavljevic - BASE - Python REST API framework
SFScon 2020 - Nikola Milisavljevic - BASE - Python REST API framework
 
How to build crud application using vue js, graphql, and hasura
How to build crud application using vue js, graphql, and hasuraHow to build crud application using vue js, graphql, and hasura
How to build crud application using vue js, graphql, and hasura
 
Lab 5-Android
Lab 5-AndroidLab 5-Android
Lab 5-Android
 
-Kotlin_Camp_Unit2.pptx
-Kotlin_Camp_Unit2.pptx-Kotlin_Camp_Unit2.pptx
-Kotlin_Camp_Unit2.pptx
 
-Kotlin Camp Unit2.pptx
-Kotlin Camp Unit2.pptx-Kotlin Camp Unit2.pptx
-Kotlin Camp Unit2.pptx
 
Android application architecture
Android application architectureAndroid application architecture
Android application architecture
 
Appcelerator Titanium Alloy + Kinvey Collection Databinding - Part One
Appcelerator Titanium Alloy + Kinvey Collection Databinding - Part OneAppcelerator Titanium Alloy + Kinvey Collection Databinding - Part One
Appcelerator Titanium Alloy + Kinvey Collection Databinding - Part One
 
Schema-First API Design
Schema-First API DesignSchema-First API Design
Schema-First API Design
 
Cloud native programming model comparison
Cloud native programming model comparisonCloud native programming model comparison
Cloud native programming model comparison
 
Paper trail gem
Paper trail gemPaper trail gem
Paper trail gem
 
Angularjs2 presentation
Angularjs2 presentationAngularjs2 presentation
Angularjs2 presentation
 
iOS Swift application architecture
iOS Swift application architectureiOS Swift application architecture
iOS Swift application architecture
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQL
 
Basic iOS Training with SWIFT - Part 4
Basic iOS Training with SWIFT - Part 4Basic iOS Training with SWIFT - Part 4
Basic iOS Training with SWIFT - Part 4
 

Recently uploaded

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 

Recently uploaded (20)

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 

apiDoc Introduction

  • 1. APIDOCInline Documentation for RESTful web APIs Introduction with a small example. http://apidocjs.com
  • 2. What does apiDoc ? apiDoc … creates a Documentation HTML-Page … use API-Descriptions from your source code For who ? apiDoc can be used with any programming language, that allow block documentation: /** * This is a comment. */
  • 3. Where i find apiDoc ? apiDoc is Open Source and distributed over NPM and github Visit: http://apidocjs.com Special functions apiDoc … support own created Templates … includes History … compare old and new API-Method Versions … allows frontend Developer to see what changed … support Inherit … reuse of Documentation parts … extendable … you can create your own Documentation Methods
  • 4. Ok, let us begin... apiDoc is a node module, so install Node.js first: http://nodejs.org Node.js includes „npm“, a package manager for node. Install apiDoc [sudo] npm install -g apidoc We install apiDoc global, so you can access it from everywhere.
  • 5. EXAMPLE PROJECT We use a simple static JavaScript example. We ignore routing, validation or database operations. This are only small parts of apiDocs functions, for all visit http://apidocjs.com There is also a complex example: http://apidocjs.com/#example-full
  • 6. Create a new directory „my_project“. Within that dir create a file „example.js“. example.js var currentUser = { name: 'Mary' }; function getUser() { return { code: 200, data: currentUser }; } function setName(name) { if(name.length === 0) { return { code: 404, message: 'NameEmptyError' }; } currentUser.name = name; return { code: 204 }; }
  • 7. A basic doc Above „function getUser“ we place a basic documentation block /** * @api {get} /user Request User information * @apiName GetUser * @apiGroup User */ function getUser() { return { code: 200, data: currentUser }; } This 3 parameters are required! @api describes the path of the Method that clients call. @apiName is a unique Name, you can name as you want, for simplicity i prefer „Type of Method“ + „Name of Method“ e.g. {get} and „/user“ => GetUser. @apiGroup is the name of the group to which this method belongs. The group will be used for Navigation.
  • 8. By default apiDoc search for all „.jjs“ files in current directory and sub directories. You can change the includeFilter, call „apidoc -h“ for details. apiDoc created a new HTML-Page in directory „doc“. From command line run within „my_project“ directory: apidoc
  • 9. Open „doc/index.html“ in your Browser We see the rudimentary Webpage, with Navigation left and Content right. We have a group „User“ and within that group an API-Method „GET /user“
  • 10. Describe the API-Answer Now we add success return parameters /** * @api {get} /user Request User information * @apiName GetUser * @apiGroup User * * @apiSuccess {String} name The users name. */ function getUser() { return { code: 200, data: currentUser }; } apidoc Run apiDoc again, it will overwrite the „doc“ Directory
  • 11. Now we have a little more Information and see what „GET /user“ returns on a successful reply „Success 200“.
  • 12. Add a Version and example Code We add a Version (Format “major.minor.patch”, see http://semver.org for details) and we add an example code, that shows what will be return in case of success /** * @api {get} /user Request User information * @apiName GetUser * @apiGroup User * @apiVersion 0.1.0 * * @apiSuccess {String} name The users name. * * @apiSuccessExample Example data on success: * { * name: 'Paul' * } */ function getUser() { return { code: 200, data: currentUser }; }
  • 13. In the right dropdown box we see now the Version „0.1.0“ and under „Success 200“ our integrated example.
  • 14. VERSIONING If you work in a Team and some Programmer work an the API backend and some on Frontend Client, it is important to know what changed in a new Release. Especially during developing an Application, many things can change.
  • 15. An API Method change Create a new file „_apidoc.js“. Put only the documentation Block from „getUser“ in that file: _apidoc.js /** * @api {get} /user Request User information * @apiName GetUser * @apiGroup User * @apiVersion 0.1.0 * * @apiSuccess {String} name The users name. * * @apiSuccessExample Example data on success: * { * name: 'Paul' * } */ „_apidoc.js“ will be our history file and contains old documentation blocks.
  • 16. Now we change the documentation block in „example.js“ example.js /** * @api {get} /user Request User information * @apiName GetUser * @apiGroup User * @apiVersion 0.2.0 * * @apiSuccess {String} name The users name. * @apiSuccess {Number} age Calculated age from Birthday * * @apiSuccessExample Example data on success: * { * name: 'Paul', * age: 27 * } */ function getUser() { return { code: 200, data: currentUser }; }
  • 17. After call „apidoc“ and open „doc/index.html“ you see now Version „0.2.0“ with the Field „age“ and the changed example.
  • 18. And now the magic...
  • 19. Select from Dropdown „0.2.0“ the Version „0.1.0“. You see now a comparison from the 2 Versions. Green marked content indicates the Fields that are added to Version „0.2.0“.
  • 20. In the future, when you made more changes to an API-Method, simply copy and add the complete documentation block to the history file „_apidoc.js“. Leave the old blocks as they are. Then you have a Documentation where everybody can see any change of your API.
  • 21. PARAMS AND ERRORS We take now a quick look at how to add Parameters, that an API-Method need and how we return errors.
  • 22. We add now a documentation to our second function „setName“. example.js /** * @api {put} /user Change User * @apiName PutUser * @apiGroup User * @apiVersion 0.1.0 * * @apiParam {String} name New name of the user * * @apiError NameEmptyError The name was empty. Minimum of <code>1</code> character is required. */ function setName(name) { if(name.length === 0) { return { code: 404, message: 'NameEmptyError' }; } currentUser.name = name; return { code: 204 }; }
  • 23. You will see now the new „Change User“ entry in navigation and the content for the API-Method.
  • 24. Thank you and have a productive use ! For more Information visit http://apidocjs.com Author: Peter Rottmann peter@apidocjs.com