%3CLINGO-SUB%20id%3D%22lingo-sub-1869627%22%20slang%3D%22en-US%22%3EBuild%20REST%20APIs%20in%20three%20steps%20with%20API%20Management%20and%20Azure%20Functions%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1869627%22%20slang%3D%22en-US%22%3E%3CP%3EImagine%20you%20build%20an%20API%20only%20to%20realize%20later%20down%20the%20road%2C%20your%20documentation%20for%20it%20isn%E2%80%99t%20kept%20up%20to%20date%20and%20you%20are%20now%20spending%20more%20time%20trying%20to%20figure%20how%20it%20works%20than%20it%20took%20to%20build.%20Sound%20familiar%3F%20This%20is%20one%20of%20the%20common%20pitfalls%20of%20a%20code-first%20approach%20to%20APIs.%20There%20are%20two%20key%20approaches%20to%20building%20APIs%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3ECode-first%3C%2FSTRONG%3E%3A%20coding%20the%20API%20directly%20from%20the%20requirements%20and%20then%20generating%20an%20API%20definition%20document%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EDesign-first%3C%2FSTRONG%3E%3A%20defining%20an%20API%20first%20and%20then%20implementing%20backend%20services%20based%20on%20the%20agreed%20API%20design%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EIf%20you%20were%20to%20follow%20a%20design-first%20approach%2C%20you%20can%20design%20your%20API%20in%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fapi-management%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAPI%20Management%3C%2FA%3E%20and%20export%20it%20to%20an%20OpenAPI%20specification%20file%2C%20which%20could%20be%20used%20to%20bring%20organizational%20alignment%20and%20serve%20as%20a%20guidance%20for%20implementing%20backend%20services%20that%20support%20the%20API%20logic%20and%20client%20applications%20that%20consume%20the%20API.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20support%20the%20design-first%20approach%2C%20we%20recently%20released%20an%20update%20to%20our%20Azure%20Functions%20and%20API%20Management%20Visual%20Studio%20Code%20extensions%20that%20lets%20you%20generate%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fazure-funcitons%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20Function%3C%2FA%3E%20apps%20by%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fauto-rest-azure-functions%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eimporting%20an%20OpenAPI%20specification%3C%2FA%3E%3CSPAN%3E.%20The%20same%20functionality%20is%20available%3C%2FSPAN%3E%20via%20the%20command%20line.%3C%2FP%3E%0A%3CP%3EFunctions%20provide%20not%20only%20ready-made%20scaffolding%20for%20writing%20an%20API%20but%20all%20the%20necessary%20hosting.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFunctions%20allow%20your%20API%20to%20dynamically%20scale%20up%20or%20down%20depending%20on%20the%20number%20of%20requests.%20Since%20it%20is%20consumption-based%2C%20you're%20only%20charged%20when%20an%20HTTP%20endpoint%20is%20called%2C%20and%20you%20aren%E2%80%99t%20paying%20for%20idle%20resources%20as%20you%20would%20if%20you%20were%20using%20a%20VM%20as%20a%20host.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1209473548%22%20id%3D%22toc-hId--1209473548%22%20id%3D%22toc-hId--1209473548%22%20id%3D%22toc-hId--1209473548%22%20id%3D%22toc-hId--1209473548%22%20id%3D%22toc-hId--1209473548%22%3EExample%20Scenario%3C%2FH2%3E%0A%3CP%3EImagine%20a%20scenario%20where%20you%20are%20creating%20an%20API%20for%20a%20food%20delivery%20service.%20After%20gathering%20the%20business%20requirements%2C%20you%20begin%20developing%20the%20API.%20Once%20the%20API%20is%20built%2C%20dependent%20teams%20start%20testing%2C%20documenting%2C%20and%20providing%20feedback.%20But%20while%20gathering%20feedback%20you%20realize%20you%20need%20to%20pivot%20and%20rewrite%20a%20significant%20portion%20of%20your%20API%20which%20is%20going%20to%20push%20back%20the%20project.%20That%E2%80%99s%20where%20the%20code-first%20approach%20falls%20short.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhat%20if%20instead%20of%20developing%20the%20API%2C%20you%20started%20with%20an%20API%20description%20to%20establish%20a%20shared%20understanding%20of%20how%20the%20API%20is%20supposed%20to%20function.%20During%20the%20process%20of%20creating%20the%20description%20you%20start%20asking%20questions%20like%3A%20What%20functionality%20will%20the%20API%20have%3F%20What%20will%20the%20developer%20experience%20be%20like%3F%20What%20data%20will%20it%20expose%20and%20in%20what%20format%3F%20How%20will%20we%20add%20new%20functionality%20in%20the%20future%3F%20To%20answer%20some%20of%20these%20questions%20you%20need%20to%20bring%20in%20other%20teams%20to%20provide%20input.%20You%20can%20now%20get%20earlier%20validation%20on%20the%20API%20functionality%20from%20various%20stakeholders%20while%20the%20cost%20of%20making%20changes%20are%20low.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20addition%20to%20gathering%20feedback%20earlier%20in%20the%20API%20development%20process%2C%20teams%20that%20are%20consumers%20of%20the%20API%20can%20begin%20testing%20and%20integration%20before%20the%20business%20logic%20is%20complete.%20Dependent%20teams%20are%20not%20blocked%20by%20another%20team%E2%80%99s%20progress%20and%20can%20work%20in%20parallel%20during%20API%20development%20process.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1278039285%22%20id%3D%22toc-hId-1278039285%22%20id%3D%22toc-hId-1278039285%22%20id%3D%22toc-hId-1278039285%22%20id%3D%22toc-hId-1278039285%22%20id%3D%22toc-hId-1278039285%22%3EWhich%20approach%20should%20I%20use%3F%3C%2FH2%3E%0A%3CP%3EDetermining%20what%20approach%20to%20use%20will%20depend%20on%20your%20business%20needs%20and%20use%20case.%20The%20code-first%20approach%20is%20a%20more%20traditional%20approach%20to%20building%20APIs%2C%20but%20the%20popularity%20of%20API%20definition%20formats%20has%20led%20to%20the%20growing%20support%20of%20the%20design-first%20methodology.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDesign-first%20allows%20consumers%20to%20better%20understand%20of%20how%20to%20use%20your%20API%20and%20ensures%20consistency%20across%20APIs.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EKey%20benefits%20of%20a%20design-first%20approach%20are%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EAccelerates%20API%20development%20by%20establishing%20key%20details%20in%20the%20design%20phase%20and%20allowing%20development%20teams%20to%20work%20in%20parallel%3C%2FLI%3E%0A%3CLI%3EResults%20in%20a%20transparent%20API%20documentation%20to%20stakeholders%3C%2FLI%3E%0A%3CLI%3ELet%E2%80%99s%20you%20focus%20on%20the%20API%20consumer%20experience%20and%20the%20business%20logic%20that%20the%20API%20fulfills%2C%20detaching%20it%20from%20the%20technical%20implementation%3C%2FLI%3E%0A%3CLI%3EHelps%20to%20create%20a%20strong%20foundation%20for%20the%20API%2C%20which%20may%20reduce%20the%20number%20of%20breaking%20changes%20in%20future%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--529415178%22%20id%3D%22toc-hId--529415178%22%20id%3D%22toc-hId--529415178%22%20id%3D%22toc-hId--529415178%22%20id%3D%22toc-hId--529415178%22%20id%3D%22toc-hId--529415178%22%3EBuilding%20a%20REST%20API%20in%20three%20steps%3C%2FH2%3E%0A%3CP%3EIn%20three%20easy%20steps%20you%20can%20design%20and%20build%20your%20API%E2%80%99s%20without%20writing%20a%20bunch%20of%20lines%20of%20code%20and%20documentation.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%201%3A%20Create%20an%20API%20definition%20using%20API%20Management%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EIn%20API%20Management%2C%20choose%20API%E2%80%99s%20from%20the%20left%20menu%2C%20and%20then%20select%20OpenAPI.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22sheltongraves_0-1604965662842.png%22%20style%3D%22width%3A%20734px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F232456iCA1BF5687BCEE3F9%2Fimage-dimensions%2F734x290%3Fv%3D1.0%22%20width%3D%22734%22%20height%3D%22290%22%20role%3D%22button%22%20title%3D%22sheltongraves_0-1604965662842.png%22%20alt%3D%22sheltongraves_0-1604965662842.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20Create%20from%20OpenAPI%20specification%20window%2C%20select%20Full.%20Fill%20in%20your%20API%20values%20in%20the%20necessary%20fields%20and%20select%20create.%20Here%20is%20a%20sample%20Open%20API%20file%20you%20can%20%3CA%20href%3D%22https%3A%2F%2Fconferenceapi.azurewebsites.net%2F%3Fformat%3Djson%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Euse%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22sheltongraves_1-1604964910819.png%22%20style%3D%22width%3A%20709px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F232445i79D08FD656EE425A%2Fimage-dimensions%2F709x533%3Fv%3D1.0%22%20width%3D%22709%22%20height%3D%22533%22%20role%3D%22button%22%20title%3D%22sheltongraves_1-1604964910819.png%22%20alt%3D%22sheltongraves_1-1604964910819.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%202%3A%20Generate%20function%20apps%20from%20Open%20API%20Specifications%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ENow%20that%20you%20have%20created%20an%20OpenAPI%20specification%20file%20you%20can%20import%20the%20specification%20via%20the%20%26nbsp%3BAPI%20Management%20or%20Azure%20Functions%20VS%20Code%20extensions%20to%20create%20the%20scaffolding%20for%20your%20API.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGetting%20started%20with%20VS%20Code%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EBefore%20you%20get%20started%20there%E2%80%99s%20a%20few%20things%20you%20will%20need%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fcode.visualstudio.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EVisual%20Studio%20Code%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3ELatest%20version%20of%20the%20%3CA%20href%3D%22https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dms-azuretools.vscode-azurefunctions%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20Functions%20extension%3C%2FA%3E%3CSPAN%3E%20or%20%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dms-azuretools.vscode-apimanagement%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAPI%20Management%20Extension%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3EYou%20will%20need%20the%20correct%20language%20runtimes%20installed%20for%20the%20type%20of%20function%20app%20you%20want%20to%20create.%20The%20languages%20we%20currently%20support%20are%20C%23%2C%20Python%2C%20TypeScript%2C%20and%20Java.%20Support%20for%20JavaScript%20and%20PowerShell%20coming%20in%20the%20near%20future.%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fautorest.azure-functions%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAutoRest%3C%2FA%3E%20(Microsoft's%20OpenAPI%20specification%20generator)%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EFrom%20API%20Management%20Extension%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EIn%20your%20VS%20code%20settings%20make%20sure%20you%20enable%20the%20API%20Management%20extension%20to%20create%20Functions.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22sheltongraves_2-1604964910824.jpeg%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F232446iC83DD76FA08E787D%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22sheltongraves_2-1604964910824.jpeg%22%20alt%3D%22sheltongraves_2-1604964910824.jpeg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20API%20management%20VS%20code%20extension%20right%20click%20on%20the%20API%20definition%20you%20would%20like%20to%20use%20and%20select%20scaffold%20Azure%20Functions.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22sheltongraves_0-1605044260943.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F232765i43779291F11BB907%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22sheltongraves_0-1605044260943.png%22%20alt%3D%22sheltongraves_0-1605044260943.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESelect%20your%20language%20of%20choice%20and%20where%20you%20would%20like%20to%20create%20the%20functions.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22sheltongraves_4-1604964910882.png%22%20style%3D%22width%3A%20556px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F232448iE667BFEF2E2E3C76%2Fimage-dimensions%2F556x135%3Fv%3D1.0%22%20width%3D%22556%22%20height%3D%22135%22%20role%3D%22button%22%20title%3D%22sheltongraves_4-1604964910882.png%22%20alt%3D%22sheltongraves_4-1604964910882.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWatch%20as%20it%20starts%20to%20generate%20function%20apps%20from%20your%20specification%20file!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22stencilapimanage.gif%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F232461i3662DA4252CE7389%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22stencilapimanage.gif%22%20alt%3D%22stencilapimanage.gif%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EFrom%20Azure%20Functions%20Extension%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EYou%20can%20also%20use%20the%20Azure%20Functions%20extension%20to%20import%20a%20specification%20to%20create%20the%20scaffolding%20for%20your%20API.%3C%2FP%3E%0A%3CP%3ECreate%20a%20new%20function%20app%20and%20choose%20your%20language%20of%20choice%20(TypeScript%2C%20Python%2C%20C%23).%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22sheltongraves_6-1604964911054.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F232451i37DC4E2A0E6D10AB%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22sheltongraves_6-1604964911054.png%22%20alt%3D%22sheltongraves_6-1604964911054.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESelect%20the%20HTTP%20trigger(s)%20from%20OpenAPI%20V2%2FV3%20Specification%20template.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22sheltongraves_7-1604964911059.png%22%20style%3D%22width%3A%20471px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F232452i6E26E7C8FB339BE8%2Fimage-dimensions%2F471x352%3Fv%3D1.0%22%20width%3D%22471%22%20height%3D%22352%22%20role%3D%22button%22%20title%3D%22sheltongraves_7-1604964911059.png%22%20alt%3D%22sheltongraves_7-1604964911059.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESelect%20your%20OpenAPI%20specification%20file%20(You%20can%20find%20some%20samples%20to%20try%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FOAI%2FOpenAPI-Specification%2Ftree%2Fmaster%2Fexamples%2Fv3.0%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22sheltongraves_8-1604964911060.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F232453iC3A9E7CD21F5DA50%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22sheltongraves_8-1604964911060.png%22%20alt%3D%22sheltongraves_8-1604964911060.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%203%3A%20Add%20your%20business%20logic%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EOnce%20it%20completes%20you%20will%20see%20it%20has%20automatically%20generated%20all%20the%20necessary%20functions%20for%20your%20API%2C%20preconfigured%20based%20on%20the%20OpenAPI%20specification.%20All%20you%20need%20to%20do%20now%20is%20add%20your%20business%20logic%20to%20each%20function%2Froute%20and%20deploy%20to%20Azure.%3C%2FP%3E%0A%3CDIV%20id%3D%22tinyMceEditorsheltongraves_11%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22sheltongraves_9-1604964911062.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F232454iAE1D7D9FDD2E5A4F%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22sheltongraves_9-1604964911062.png%22%20alt%3D%22sheltongraves_9-1604964911062.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGetting%20started%20with%20CLI%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EYou%20can%20also%20use%20the%20CLI%20as%20well%20to%20create%20the%20scaffolding%20for%20your%20API%E2%80%99s.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3Eautorest%20--azure-functions-csharp%20%5C%0A%0A%20%20%20%20%20%20%20%20%20--input-file%3A%2Fpath%2Fto%2Fspec.json%20%5C%0A%0A%20%20%20%20%20%20%20%20%20--output-folder%3A.%2Fgenerated-azfunctions%20%5C%0A%0A%20%20%20%20%20%20%20%20%20--version%3A3.0.6314%20%5C%0A%0A%20%20%20%20%20%20%20%20%20--namespace%3ANamespace%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECheck%20out%20the%20GitHub%20repo%20for%20more%20information%20on%20how%20to%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fauto-rest-azure-functions%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eget%20started%3C%2FA%3E%3CSPAN%3E.%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1958097655%22%20id%3D%22toc-hId-1958097655%22%20id%3D%22toc-hId-1958097655%22%20id%3D%22toc-hId-1958097655%22%20id%3D%22toc-hId-1958097655%22%20id%3D%22toc-hId-1958097655%22%3ESummary%3C%2FH2%3E%0A%3CP%3EThe%20design-first%20approach%20to%20building%20APIs%20comes%20with%20many%20benefits%2C%20saving%20you%20time%20and%20effort%20in%20bringing%20your%20APIs%20to%20market.%20Now%20you%20can%20reap%20the%20benefits%20even%20more%20by%20generating%20the%20Azure%20Functions%20scaffolding%20for%20your%20APIs%20from%20OpenAPI%20definition%20in%20Visual%20Studio%20Code.%20If%20you%20have%20an%20existing%20API%20hosted%20on%20Azure%20and%20you%E2%80%99re%20interested%20in%20exploring%20a%20serverless%20architecture%20or%20consumption-based%20billing%20model%2C%20this%20new%20capability%20is%20a%20fast%20track%20for%20getting%20started%20with%20Azure%20Functions.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20learn%20more%20about%20building%20serverless%20APIs%20with%20Azure%20Functions%20and%20Azure%20API%20Management%2C%20check%20out%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fazure-sample-serverless-apis%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ea%20new%20workshop%20we%20recently%20published%20on%20GitHub%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1869627%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22openapi.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F232444i6F3C619AF8F92FBE%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22openapi.png%22%20alt%3D%22openapi.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EDesign%20and%20build%20REST%20APIs%20in%20three%20steps%20by%20generating%20Function%20apps%20from%20an%20OpenAPI%20specification%20file%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1869627%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EServerless%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1885988%22%20slang%3D%22en-US%22%3ERe%3A%20Build%20REST%20APIs%20in%20three%20steps%20with%20API%20Management%20and%20Azure%20Functions%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1885988%22%20slang%3D%22en-US%22%3E%3CP%3EMissing%20in%20the%20post%2C%20the%20feature%20is%20not%20enabled%20by%20default%26nbsp%3Bw.r.t%20API%20Management%20Extension%2C%20it%20a%20experimental%20feature%20and%20needs%20to%20be%20enabled%20via%20Advanced%20Settings%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22anganti_0-1605299499974.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F233501iD3BF645022A301C3%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22anganti_0-1605299499974.png%22%20alt%3D%22anganti_0-1605299499974.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Microsoft

Imagine you build an API only to realize later down the road, your documentation for it isn’t kept up to date and you are now spending more time trying to figure how it works than it took to build. Sound familiar? This is one of the common pitfalls of a code-first approach to APIs. There are two key approaches to building APIs:

  • Code-first: coding the API directly from the requirements and then generating an API definition document
  • Design-first: defining an API first and then implementing backend services based on the agreed API design

If you were to follow a design-first approach, you can design your API in API Management and export it to an OpenAPI specification file, which could be used to bring organizational alignment and serve as a guidance for implementing backend services that support the API logic and client applications that consume the API.

 

To support the design-first approach, we recently released an update to our Azure Functions and API Management Visual Studio Code extensions that lets you generate Azure Function apps by importing an OpenAPI specification. The same functionality is available via the command line.

Functions provide not only ready-made scaffolding for writing an API but all the necessary hosting.

 

Functions allow your API to dynamically scale up or down depending on the number of requests. Since it is consumption-based, you're only charged when an HTTP endpoint is called, and you aren’t paying for idle resources as you would if you were using a VM as a host.

 

Example Scenario

Imagine a scenario where you are creating an API for a food delivery service. After gathering the business requirements, you begin developing the API. Once the API is built, dependent teams start testing, documenting, and providing feedback. But while gathering feedback you realize you need to pivot and rewrite a significant portion of your API which is going to push back the project. That’s where the code-first approach falls short.

 

What if instead of developing the API, you started with an API description to establish a shared understanding of how the API is supposed to function. During the process of creating the description you start asking questions like: What functionality will the API have? What will the developer experience be like? What data will it expose and in what format? How will we add new functionality in the future? To answer some of these questions you need to bring in other teams to provide input. You can now get earlier validation on the API functionality from various stakeholders while the cost of making changes are low.

 

In addition to gathering feedback earlier in the API development process, teams that are consumers of the API can begin testing and integration before the business logic is complete. Dependent teams are not blocked by another team’s progress and can work in parallel during API development process.

 

Which approach should I use?

Determining what approach to use will depend on your business needs and use case. The code-first approach is a more traditional approach to building APIs, but the popularity of API definition formats has led to the growing support of the design-first methodology.

 

Design-first allows consumers to better understand of how to use your API and ensures consistency across APIs.

 

Key benefits of a design-first approach are:

  • Accelerates API development by establishing key details in the design phase and allowing development teams to work in parallel
  • Results in a transparent API documentation to stakeholders
  • Let’s you focus on the API consumer experience and the business logic that the API fulfills, detaching it from the technical implementation
  • Helps to create a strong foundation for the API, which may reduce the number of breaking changes in future

 

Building a REST API in three steps

In three easy steps you can design and build your API’s without writing a bunch of lines of code and documentation.

 

Step 1: Create an API definition using API Management

In API Management, choose API’s from the left menu, and then select OpenAPI.

sheltongraves_0-1604965662842.png

 

In the Create from OpenAPI specification window, select Full. Fill in your API values in the necessary fields and select create. Here is a sample Open API file you can use.

sheltongraves_1-1604964910819.png

 

Step 2: Generate function apps from Open API Specifications

Now that you have created an OpenAPI specification file you can import the specification via the  API Management or Azure Functions VS Code extensions to create the scaffolding for your API.

Getting started with VS Code

Before you get started there’s a few things you will need:

  • Visual Studio Code
  • Latest version of the Azure Functions extension or API Management Extension
  • You will need the correct language runtimes installed for the type of function app you want to create. The languages we currently support are C#, Python, TypeScript, and Java. Support for JavaScript and PowerShell coming in the near future.
  • AutoRest (Microsoft's OpenAPI specification generator)

 

From API Management Extension

In your VS code settings make sure you enable the API Management extension to create Functions.

sheltongraves_2-1604964910824.jpeg

 

In the API management VS code extension right click on the API definition you would like to use and select scaffold Azure Functions.

 

sheltongraves_0-1605044260943.png

 

Select your language of choice and where you would like to create the functions.

 

sheltongraves_4-1604964910882.png

 

Watch as it starts to generate function apps from your specification file!

 

stencilapimanage.gif

 

From Azure Functions Extension

You can also use the Azure Functions extension to import a specification to create the scaffolding for your API.

Create a new function app and choose your language of choice (TypeScript, Python, C#).

sheltongraves_6-1604964911054.png

 

Select the HTTP trigger(s) from OpenAPI V2/V3 Specification template.

 

sheltongraves_7-1604964911059.png

 

Select your OpenAPI specification file (You can find some samples to try here).

 

sheltongraves_8-1604964911060.png

 

Step 3: Add your business logic

Once it completes you will see it has automatically generated all the necessary functions for your API, preconfigured based on the OpenAPI specification. All you need to do now is add your business logic to each function/route and deploy to Azure.

 

sheltongraves_9-1604964911062.png

 

Getting started with CLI

You can also use the CLI as well to create the scaffolding for your API’s.

 

 

 

 

 

autorest --azure-functions-csharp \

         --input-file:/path/to/spec.json \

         --output-folder:./generated-azfunctions \

         --version:3.0.6314 \

         --namespace:Namespace

 

 

 

 

 

Check out the GitHub repo for more information on how to get started.

 

Summary

The design-first approach to building APIs comes with many benefits, saving you time and effort in bringing your APIs to market. Now you can reap the benefits even more by generating the Azure Functions scaffolding for your APIs from OpenAPI definition in Visual Studio Code. If you have an existing API hosted on Azure and you’re interested in exploring a serverless architecture or consumption-based billing model, this new capability is a fast track for getting started with Azure Functions.

 

To learn more about building serverless APIs with Azure Functions and Azure API Management, check out a new workshop we recently published on GitHub.

 

1 Comment
Microsoft

Missing in the post, the feature is not enabled by default w.r.t API Management Extension, it a experimental feature and needs to be enabled via Advanced Settings

 

anganti_0-1605299499974.png