{"id":3001,"date":"2025-01-07T20:16:28","date_gmt":"2025-01-08T02:16:28","guid":{"rendered":"https:\/\/readme.com\/resources\/?p=3001"},"modified":"2025-01-07T20:16:29","modified_gmt":"2025-01-08T02:16:29","slug":"basic-oas-server-variables-support","status":"publish","type":"post","link":"https:\/\/readme.com\/resources\/basic-oas-server-variables-support","title":{"rendered":"Basic OAS Server Variables Support in API Explorer"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><em>Update (Feb 18th, 2022): We\u2019ve since shipped support for enums and you can now manually enter Server Variables via &lt;input&gt;. We\u2019ve updated the content below to reflect this!<\/em><\/p>\n<\/blockquote>\n\n\n\n<p>OAS 3 introduced the concept of&nbsp;<a href=\"https:\/\/github.com\/OAI\/OpenAPI-Specification\/blob\/39d133d34a0acae12ed66fc0a25f7ec4dc1b9391\/versions\/3.0.0.md?ref=blog.readme.com#server-variable-object\">Server Variables<\/a>. This allows you to configure changeable parts of your API&#8217;s URL. Here\u2019s an example from the spec:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"JavaScript\" class=\"language-JavaScript\">{\n  \"servers\": [\n    {\n      \"url\": \"https:\/\/{username}.gigantic-server.com:{port}\/{basePath}\",\n      \"description\": \"The production API server\",\n      \"variables\": {\n        \"username\": {\n          \"default\": \"demo\",\n          \"description\": \"this value is assigned by the service provider, in this example `gigantic-server.com`\"\n        },\n        \"port\": {\n          \"enum\": [\n            \"8443\",\n            \"443\"\n          ],\n          \"default\": \"8443\"\n        },\n        \"basePath\": {\n          \"default\": \"v2\"\n        }\n      }\n    }\n  ]\n}\n<\/code><\/pre>\n\n\n\n<p>This tells your API consumers that the&nbsp;<code>{variable}<\/code>&nbsp;parts in the URL are changeable.<\/p>\n\n\n\n<p>Today we\u2019re introducing support for Server Variables in our&nbsp;<a href=\"https:\/\/github.com\/readmeio\/api-explorer?ref=blog.readme.com\">API Explorer<\/a>&nbsp;if you&#8217;re using&nbsp;<a href=\"https:\/\/docs.readme.com\/docs\/custom-login-with-readme?ref=blog.readme.com#jwt-setup\">JWT Login<\/a>&nbsp;to get your user data into your docs. For the above example, you would pass the following user object:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"JavaScript\" class=\"language-JavaScript\">{\n  name: 'Dom H',\n  email: 'dom@readme.io',\n  username: 'domh',\n  port: 3000,\n  basePath: 'custom-base-path'\n  version: 1, \/\/ Required, if omited things can break unexpectedly\n}\n<\/code><\/pre>\n\n\n\n<p>This would result in the following URL:<\/p>\n\n\n\n<figure class=\"wp-block-embed\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/domh.gigantic-server.com:3000\/custom-base-path\n<\/div><\/figure>\n\n\n\n<p>You can see a live demo of this in action over on our demo site:<\/p>\n\n\n\n<figure class=\"wp-block-embed\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/preview.readme.io\/?url=server-variables.json\n<\/div><\/figure>\n\n\n\n<p>The OAS file backing this example is&nbsp;<a href=\"https:\/\/github.com\/readmeio\/api-explorer\/blob\/7963c659cd927486abf0d15b4f7a4f8622722aca\/example\/swagger-files\/server-variables.json?ref=blog.readme.com\">here<\/a>.<\/p>\n\n\n\n<p>We&#8217;re really excited for this feature as it enables you to generate completely custom URLs for each of your customers, while also providing a fallback for those who are not logged in.<\/p>\n\n\n\n<p>This does have some limitations at the moment:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><s>no\u00a0<\/s><a href=\"https:\/\/github.com\/OAI\/OpenAPI-Specification\/blob\/39d133d34a0acae12ed66fc0a25f7ec4dc1b9391\/versions\/3.0.0.md?ref=blog.readme.com#fixed-fields-5\"><s>enums<\/s><\/a><s>\u00a0support<\/s>\u00a0now supported<\/li>\n\n\n\n<li><s>no top-level input to enter in server variables that are not provided via JWT<\/s>\u00a0now supported<\/li>\n\n\n\n<li>not currently working for Manual APIs defined within ReadMe<\/li>\n<\/ul>\n\n\n\n<p>If you require these things, let us know by emailing support@readme.io and we can discuss them with you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update (Feb 18th, 2022): We\u2019ve since shipped support for enums and you can now manually enter Server Variables via &lt;input&gt;. We\u2019ve updated the content below to reflect this! OAS 3 introduced the concept of&nbsp;Server Variables. This allows you to configure changeable parts of your API&#8217;s URL. Here\u2019s an example from the spec: This tells your [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","inline_featured_image":false,"footnotes":""},"categories":[22],"tags":[],"ppma_author":[53],"class_list":["post-3001","post","type-post","status-publish","format-standard","hentry","category-api-tips"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Getting Started with Server Variables in OpenAPI<\/title>\n<meta name=\"description\" content=\"Learn how to use OpenAPI server variables to make your API endpoints more adaptable and environment-friendly.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/readme.com\/resources\/basic-oas-server-variables-support\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Getting Started with Server Variables in OpenAPI\" \/>\n<meta property=\"og:description\" content=\"Learn how to use OpenAPI server variables to make your API endpoints more adaptable and environment-friendly.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/readme.com\/resources\/basic-oas-server-variables-support\" \/>\n<meta property=\"og:site_name\" content=\"ReadMe: Resource Library\" \/>\n<meta property=\"article:published_time\" content=\"2025-01-08T02:16:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-08T02:16:29+00:00\" \/>\n<meta name=\"author\" content=\"Dom Harrington\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Miche Nickolaisen\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/readme.com\/resources\/basic-oas-server-variables-support\",\"url\":\"https:\/\/readme.com\/resources\/basic-oas-server-variables-support\",\"name\":\"Getting Started with Server Variables in OpenAPI\",\"isPartOf\":{\"@id\":\"https:\/\/readme.com\/resources\/#website\"},\"datePublished\":\"2025-01-08T02:16:28+00:00\",\"dateModified\":\"2025-01-08T02:16:29+00:00\",\"author\":{\"@id\":\"https:\/\/readme.com\/resources\/#\/schema\/person\/770bcc036178743133b5ba515195981b\"},\"description\":\"Learn how to use OpenAPI server variables to make your API endpoints more adaptable and environment-friendly.\",\"breadcrumb\":{\"@id\":\"https:\/\/readme.com\/resources\/basic-oas-server-variables-support#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/readme.com\/resources\/basic-oas-server-variables-support\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/readme.com\/resources\/basic-oas-server-variables-support#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/readme.com\/resources\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Basic OAS Server Variables Support in API Explorer\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/readme.com\/resources\/#website\",\"url\":\"https:\/\/readme.com\/resources\/\",\"name\":\"ReadMe: Resource Library\",\"description\":\"Making API documentation better for everyone\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/readme.com\/resources\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/readme.com\/resources\/#\/schema\/person\/770bcc036178743133b5ba515195981b\",\"name\":\"Miche Nickolaisen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/readme.com\/resources\/#\/schema\/person\/image\/a24e32f88df84934c107cef6fa8d3223\",\"url\":\"https:\/\/readme.com\/resources\/wp-content\/uploads\/2024\/06\/IMG_7151-scaled-e1718387764646.jpg\",\"contentUrl\":\"https:\/\/readme.com\/resources\/wp-content\/uploads\/2024\/06\/IMG_7151-scaled-e1718387764646.jpg\",\"caption\":\"Miche Nickolaisen\"},\"description\":\"An Austin resident since 2009, Miche grew up in rural southwestern Missouri. When not working on ReadMe's content marketing, you can find them doing a number of hobbies, including (but not limited to) bouldering, martial arts, playing tabletop RPGs and\/or video games, bullet journaling, and making art. They live with a large menagerie of indoor pets and a smaller (outdoor) menagerie of feral cats they take care of (sometimes including a few possums and raccoons, just for good measure).\",\"url\":\"https:\/\/readme.com\/resources\/author\/miche\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Getting Started with Server Variables in OpenAPI","description":"Learn how to use OpenAPI server variables to make your API endpoints more adaptable and environment-friendly.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/readme.com\/resources\/basic-oas-server-variables-support","og_locale":"en_US","og_type":"article","og_title":"Getting Started with Server Variables in OpenAPI","og_description":"Learn how to use OpenAPI server variables to make your API endpoints more adaptable and environment-friendly.","og_url":"https:\/\/readme.com\/resources\/basic-oas-server-variables-support","og_site_name":"ReadMe: Resource Library","article_published_time":"2025-01-08T02:16:28+00:00","article_modified_time":"2025-01-08T02:16:29+00:00","author":"Dom Harrington","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Miche Nickolaisen"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/readme.com\/resources\/basic-oas-server-variables-support","url":"https:\/\/readme.com\/resources\/basic-oas-server-variables-support","name":"Getting Started with Server Variables in OpenAPI","isPartOf":{"@id":"https:\/\/readme.com\/resources\/#website"},"datePublished":"2025-01-08T02:16:28+00:00","dateModified":"2025-01-08T02:16:29+00:00","author":{"@id":"https:\/\/readme.com\/resources\/#\/schema\/person\/770bcc036178743133b5ba515195981b"},"description":"Learn how to use OpenAPI server variables to make your API endpoints more adaptable and environment-friendly.","breadcrumb":{"@id":"https:\/\/readme.com\/resources\/basic-oas-server-variables-support#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/readme.com\/resources\/basic-oas-server-variables-support"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/readme.com\/resources\/basic-oas-server-variables-support#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/readme.com\/resources\/"},{"@type":"ListItem","position":2,"name":"Basic OAS Server Variables Support in API Explorer"}]},{"@type":"WebSite","@id":"https:\/\/readme.com\/resources\/#website","url":"https:\/\/readme.com\/resources\/","name":"ReadMe: Resource Library","description":"Making API documentation better for everyone","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/readme.com\/resources\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/readme.com\/resources\/#\/schema\/person\/770bcc036178743133b5ba515195981b","name":"Miche Nickolaisen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/readme.com\/resources\/#\/schema\/person\/image\/a24e32f88df84934c107cef6fa8d3223","url":"https:\/\/readme.com\/resources\/wp-content\/uploads\/2024\/06\/IMG_7151-scaled-e1718387764646.jpg","contentUrl":"https:\/\/readme.com\/resources\/wp-content\/uploads\/2024\/06\/IMG_7151-scaled-e1718387764646.jpg","caption":"Miche Nickolaisen"},"description":"An Austin resident since 2009, Miche grew up in rural southwestern Missouri. When not working on ReadMe's content marketing, you can find them doing a number of hobbies, including (but not limited to) bouldering, martial arts, playing tabletop RPGs and\/or video games, bullet journaling, and making art. They live with a large menagerie of indoor pets and a smaller (outdoor) menagerie of feral cats they take care of (sometimes including a few possums and raccoons, just for good measure).","url":"https:\/\/readme.com\/resources\/author\/miche"}]}},"authors":[{"term_id":53,"user_id":0,"is_guest":1,"slug":"dom-harrington","display_name":"Dom Harrington","avatar_url":{"url":"https:\/\/readme.com\/resources\/wp-content\/uploads\/2024\/06\/1516897618298.jpeg","url2x":"https:\/\/readme.com\/resources\/wp-content\/uploads\/2024\/06\/1516897618298.jpeg"},"first_name":"Dom","last_name":"Harrington","position":"Open Source Engineer","slogan":"","description":"Dom joins the ReadMe team remotely from the UK. He enjoys cooking, long walks in the countryside and playing video games. You\u2019ll likely find him in ReadMe's open source repos frantically writing tests."}],"_links":{"self":[{"href":"https:\/\/readme.com\/resources\/wp-json\/wp\/v2\/posts\/3001","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/readme.com\/resources\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/readme.com\/resources\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/readme.com\/resources\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/readme.com\/resources\/wp-json\/wp\/v2\/comments?post=3001"}],"version-history":[{"count":0,"href":"https:\/\/readme.com\/resources\/wp-json\/wp\/v2\/posts\/3001\/revisions"}],"wp:attachment":[{"href":"https:\/\/readme.com\/resources\/wp-json\/wp\/v2\/media?parent=3001"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/readme.com\/resources\/wp-json\/wp\/v2\/categories?post=3001"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/readme.com\/resources\/wp-json\/wp\/v2\/tags?post=3001"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/readme.com\/resources\/wp-json\/wp\/v2\/ppma_author?post=3001"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}