Scalar
Beautiful API references from Swagger/OpenAPI files
README
Scalar API Reference
Generate interactive API documentations from Swagger files. Try our Demo
Features
- Uses Swagger/OpenAPI spec files
- Request examples for a ton of languages + frameworks
- Has an integrated API client
- Edit your Swagger files with a live preview
- Doesn’t look like it’s 2011
>
Join us to see upcoming features, discuss the roadmap and chat about APIs with us. 💬
Getting Started
From a CDN
- ```html
- <!doctype html>
- <html>
- <head>
- <title>API Reference</title>
- <meta charset="utf-8" />
- <meta
- name="viewport"
- content="width=device-width, initial-scale=1" />
- </head>
- <body>
- !-- Add your own OpenAPI/Swagger spec file URL here: -->
- !-- Note: this includes our proxy, you can remove the following line if you do not need it -->
- !-- data-proxy-url="https://api.scalar.com/request-proxy" -->
- <script
- id="api-reference"
- data-url="https://petstore3.swagger.io/api/v3/openapi.json"
- data-proxy-url="https://api.scalar.com/request-proxy"</script>
- !-- You can also set a full configuration object like this -->
- !-- easier for nested objects -->
- <script>
- var configuration = {
- theme: 'purple',
- }
- var apiReference = document.getElementById('api-reference')
- apiReference.dataset.configuration = JSON.stringify(configuration)
- </script>
- <script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
- </body>
- </html>
- ```
You can also use the following syntax to directly pass an OpenAPI spec:
- ```html
- <script
- id="api-reference"
- type="application/json">
- { … }
- </script>
- ```
If you’d like to add a request proxy for the API client (to avoid CORS issues):
- ```html
- <script
- id="api-reference"
- type="application/json"
- data-proxy-url="https://api.scalar.com/request-proxy">
- { … }
- </script>
- ```
With Vue.js
The API Reference is built in Vue.js. If you’re working in Vue.js, too, you can directly use our Vue components. Just install them:
- ```bash
- npm install @scalar/api-reference
- ```
And import the ApiReference component to your app:
- ```vue
- <script setup lang="ts">
- import { ApiReference } from '@scalar/api-reference'
- </script>
- <template>
- <ApiReference />
- </template>
- ```
With React
The API Reference package is written in Vue, that shouldn’t stop you from using
it in React though! We have created a client side (untested on SSR/SSG) wrapper
in react.
- ```ts
- import { ApiReferenceReact } from '@scalar/api-reference-react'
- import React from 'react'
- function App() {
- return (
- <ApiReferenceReact
- configuration={{
- spec: {
- url: 'https://petstore.swagger.io/v2/swagger.json',
- },
- }}
- />
- )
- }
- export default App
- ```
With Nextjs
Our Next.js handler makes it easy to render a reference, just add it to an Api
route handler:
- ```ts
- // app/reference/route.ts
- import { ApiReference } from '@scalar/nextjs-api-reference'
- const config = {
- spec: {
- url: '/swagger.json',
- },
- }
- export const GET = ApiReference(config)
- ```
Read more: @scalar/nextjs-api-reference