• No results found

The rest-api package Dennis Klein dennis94.kl@gmail.com v1.4 from 2020/12/04

N/A
N/A
Protected

Academic year: 2021

Share "The rest-api package Dennis Klein dennis94.kl@gmail.com v1.4 from 2020/12/04"

Copied!
18
0
0

Bezig met laden.... (Bekijk nu de volledige tekst)

Hele tekst

(1)

The rest-api package

Dennis Klein

dennis94.kl@gmail.com

v1.4 from 2020/12/04

1

Introduction

A package to discribe a REST API for documentation.

2

Usage

GET Request with parameter

(2)

GET Request without parameter \ b e g i n { apiRoute }{ g e t }{/ a p i / s t o r a g e /}{ g e t a l i s t o f a l l s t o r a g e ’ s } \ b e g i n { r o u t e P a r a m e t e r } \ noRouteParameter { no p a r a m e t e r } \ end { r o u t e P a r a m e t e r } \ b e g i n { r o u t e R e s p o n s e }{ a p p l i c a t i o n / j s o n } \ b e g i n { r o u t e R e s p o n s e I t e m }{200}{ ok } \ b e g i n { routeResponseItemBody } [ { ” i d ” : 8 6 7 6 5 4 6 7 8 , ”name” : ” Apfelmus ” , ” c o u n t ” : 25 } , { ” i d ” : 3 4 2 5 2 3 , ”name” : ” Birnenmus ” , ” c o u n t ” : 1 } , . . . ] \ end { routeResponseItemBody } \ end { r o u t e R e s p o n s e I t e m } \ end { r o u t e R e s p o n s e } \ end { apiRoute }

(3)

\ b e g i n { r o u t e R e q u e s t }{ a p p l i c a t i o n / j s o n } \ b e g i n { routeRequestBody } { ”name” : ” Apfelmus ” , ” c o u n t ” : 25 } \ end { routeRequestBody } \ end { r o u t e R e q u e s t } \ b e g i n { r o u t e R e s p o n s e }{ a p p l i c a t i o n / j s o n } \ b e g i n { r o u t e R e s p o n s e I t e m }{200}{ ok } \ b e g i n { routeResponseItemBody } { ” i d ” : 8 6 7 6 5 4 6 7 8 , ”name” : ” Apfelmus ” , ” c o u n t ” : 25 } \ end { routeResponseItemBody } \ end { r o u t e R e s p o n s e I t e m } \ end { r o u t e R e s p o n s e } \ end { apiRoute } PUT Request

(4)
(5)

\ end { r o u t e R e s p o n s e I t e m } \ b e g i n { r o u t e R e s p o n s e I t e m }{404}{ e r r o r : s t o r a g e no t found } \ b e g i n { r o u t e R e s p o n s e I t e m B o d y } <message> s t o r a g e w i t h i d ’ 1 1 ’ n o t found ! </message> \ end { routeResponseItemBody } \ end { r o u t e R e s p o n s e I t e m } \ end { r o u t e R e s p o n s e } \ end { apiRoute }

2.1

Usercallable macros and environments

Return the main color for routes with get method.

\getGetColor

Return the border color for routes with get method.

\getGetBorderColor

Return the background color for routes with get method.

\getGetLightColor

Return the main color for routes with post method.

\getPostColor

Return the border color for routes with post method.

\getPostBorderColor

Return the background color for routes with post method.

\getPostLightColor

Return the main color for routes with put method.

\getPutColor

Return the border color for routes with put method.

\getPutBorderColor

Return the background color for routes with put method.

\getPutLightColor

Return the main color for routes with delete method.

\getDeleteColor

Return the border color for routes with delete method.

\getDeleteBorderColor

Return the background color for routes with delete method.

\getDeleteLightColor

Set \routeBreakValue true.

\noBreakRoute

Set \routeBreakValue false.

\breakRoute

Describe an endpoint with path, method and describtion. Contains other

envi-apiRoute

ronments with further information.

Describe the content type of the request. Contains the request body.

routeRequest

Describe the path parameter. Contains a list of \routeParamItem commands. If

routeParameter

no paramters excists you can use the command \noRouteParameter. Describe a parameter with name and describtion.

\routeParamItem

Show a text e.g. ’no parameter’.

\noRouteParameter

Describe the content type of the response. Contains a list of routeResponseItem

routeResponse

environments or the command \noRouteResponse. Show a text e.g. ’no response’.

\noRouteResponse

Describe the the http status code with describtion. Contains the response body.

routeResponseItem

2.2

Helper macros

Return true or false to enable/disable noBreak of a route.

\routeBreakValue

Return the main color of the current route.

(6)

Return the background color of the current route.

\methodLightColor

Return the border color of the current route.

\methodBorderColor

Set the color scheme and language with

\methodJson

lstset for the listings of the current route to json. Set the color scheme and language with

\methodXml

lstset for the listings of the current route to xml.

3

Implementation

this is my first package (c) Dennis Klein

This program can be redistributed and/or modified under the terms of the LaTeX Project Public License Distributed from CTAN archives in directory macros/la-tex/base/lppl.txt.

1\NeedsTeXFormat{LaTeX2e}

2\ProvidesPackage{restapi}[2020/02/18 REST API package]

(7)

\getPostBorderColor 24\newcommand{\getPostBorderColor}{postGreenBorder} \getPostLightColor 25\newcommand{\getPostLightColor}{postLightGreen} 26\definecolor{putOrange}{HTML}{E97500} 27\definecolor{putOrangeBorder}{HTML}{fca130} 28\definecolor{putLightOrange}{HTML}{FEF4EB} \getPutColor 29\newcommand{\getPutColor}{putOrange} \getPutBorderColor 30\newcommand{\getPutBorderColor}{putOrangeBorder} \getPutLightColor 31\newcommand{\getPutLightColor}{putLightOrange} 32\definecolor{deleteRed}{HTML}{CF3030} 33\definecolor{deleteRedBorder}{HTML}{f93e3e} 34\definecolor{deleteLightRed}{HTML}{FBEEEE} \getDeleteColor 35\newcommand{\getDeleteColor}{deleteRed} \getDeleteBorderColor 36\newcommand{\getDeleteBorderColor}{deleteRedBorder} \getDeleteLightColor 37\newcommand{\getDeleteLightColor}{deleteLightRed} color definitions for json

38\colorlet{punct}{black} 39\definecolor{background}{HTML}{EEEEEE} 40\colorlet{delimGet}{\getGetColor} 41\colorlet{numbGet}{delimGet} 42\colorlet{delimPost}{\getPostColor} 43\colorlet{numbPost}{delimPost} 44\colorlet{delimPut}{\getPutColor} 45\colorlet{numbPut}{delimPut} 46\colorlet{delimDelete}{\getDeleteColor} 47\colorlet{numbDelete}{delimDelete} json language defintions

48\lstdefinelanguage{jsonGet}{

49basicstyle=\small\ttfamily\color{black},

50numberstyle=\small\color{black},

(8)
(9)
(10)
(11)
(12)

250morestring=[s]{>}{<}, 251morecomment=[s]{<?}{?>}, 252stringstyle=\color{black}, 253identifierstyle=\color{numbPut}, 254} 255\lstdefinelanguage{xmlDelete}{ 256basicstyle=\small\ttfamily\color{black}, 257numberstyle=\small\color{numbDelete}, 258keywordstyle=\color{black}, 259commentstyle=\color{black}, 260stringstyle=\color{black}, 261frame=L, 262framesep=8pt, 263framerule=2pt, 264xleftmargin=50pt, 265xrightmargin=0pt, 266rulesep=0pt, 267backgroundcolor=\color{white}, 268numbersep=8pt, 269tabsize=4, 270showstringspaces=false, 271breaklines=false, 272morestring=[b]", 273morestring=[s]{>}{<}, 274morecomment=[s]{<?}{?>}, 275identifierstyle=\color{numbDelete}, 276} apiRoute frame style defintion

(13)
(14)
(15)
(16)

423\printDescription 424 425\rowcolor{\methodLightColor} & \\ 426\end{tabularx} 427} 428{ 429\end{mdframed} 430\endgroup 431\global\let\CT@arc@\saved@CT@arc@ 432} routeRequest 433\newenvironment{routeRequest}[1] 434{ 435\renewcommand{\bodyFormat}{#1} 436 437\arrayrulecolor{\methodColor} 438 439\begin{tabularx}{\textwidth}{X l} 440\rowcolor{\methodLightColor!20}

441\textbf{Body} & #1 \\ \hline

(17)

467\begin{tabularx}{\textwidth}{X} 468\rowcolor{\methodLightColor!20} 469\textbf{Parameter} \\ \hline 470\end{tabularx} 471 472\tabularx{\textwidth}{l X} 473} 474{ 475\endtabularx 476} routeResponse 477\newenvironment{routeResponse}[1] 478{ 479\renewcommand{\bodyFormat}{#1} 480 481\newcommand{\noRouteResponse}[1] 482{ 483\begin{tabularx}{\textwidth}{X} 484\rowcolor{\methodLightColor} 485\small{\textit{##1}} \\ 486\end{tabularx} 487} 488 489\arrayrulecolor{\methodColor} 490\begin{tabularx}{\textwidth}{X l} 491\rowcolor{\methodLightColor!20}

492\textbf{Response} & #1 \\ \hline

(18)

510{}

511\endinput

Referenties

GERELATEERDE DOCUMENTEN

4 700 jaar geleden waren Kampen, Zwolle, Deventer en Zutphen heel belangrijke steden?. De steden handelden veel

Maar schepen konden niet snel genoeg naar de Noordzee?. Daarom groef men

[r]

In één van deze landen is nu heel veel toerisme.. Dat komt door de lange,

Chinese schepen met handelswaar varen daarom vaak naar de

2 “Het prachtige rijk (…) dat zich slingert om de evenaar, als een gordel van smaragd.” Zo beschreef de schrijver Multatuli een land in Azië.. Hij bedoelde dat het een hele

Uit een online onderzoek van AXA Bank naar de huidige en toekomstige leefsituatie van de Belg, blijkt het bezitten van een woning gelukkiger te maken (88%) dan er één te huren

bestek nr:.