Skip to content

Instantly share code, notes, and snippets.

@dfinke
Last active February 23, 2019 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfinke/89f1d1d8e9f415ffd56d9836813e220c to your computer and use it in GitHub Desktop.
Save dfinke/89f1d1d8e9f415ffd56d9836813e220c to your computer and use it in GitHub Desktop.
swagger: "2.0"
info:
description: "My Math API"
title: "REST Enpoint for my Math API"
version: "1.0.0"
host: tryaf.azurewebsites.net
schemes:
- https
basePath: /
produces:
- application/json
consumes:
- application/json
paths:
/api/MathRestAPI:
get:
operationId: get_Result
summary: Do Math
parameters:
- in: query
name: operand1
type: number
description: 'A number'
default: 10
- in: query
name: operand2
type: number
description: 'A number'
default: 5
- in: query
name: targetOperation
type: string
description: 'targetOperation'
default: "plus"
responses:
'200':
description: OK
schema:
$ref: '#/definitions/mathapi'
definitions:
mathapi:
properties:
Result:
type: string
type: object
$requestBody = Get-Content $req -Raw | ConvertFrom-Json
$operand1 = $requestBody.operand1
$operand2 = $requestBody.operand2
$targetOperation = $requestBody.targetOperation
if($req_query_operand1) {$operand1=$req_query_operand1}
if($req_query_operand2) {$operand2=$req_query_operand2}
if($req_query_targetOperation) {$targetOperation=$req_query_targetOperation}
switch ($targetOperation) {
"plus" {$result = [int]$operand1 + $operand2}
"minus" {$result = [int]$operand1 - $operand2}
default {$result="Hello from the Math Rest API"}
}
$operand1
$operand2
$targetOperation
@{Result=$result} | ConvertTo-json > $res
@dfinke
Copy link
Author

dfinke commented Feb 23, 2019

irm "https://tryaf.azurewebsites.net/api/MathRestAPI?operand1=10&operand2=21&targetoperation=plus"

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment