Sign inSign up

immanuelfodor/json-server

By immanuelfodor

Updated over 3 years ago

Simple JSON server wrapper

Image
0

4.7K

immanuelfodor/json-server repository overview

Use it in Kubernetes like this:

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: flight-data
  namespace: apps
data:
  api.json: |
    {
      "flights": [
        { "id": 1, "code": "TL123", "src": "JFK", "dest": "CDG" },
        { "id": 2, "code": "TL234", "src": "CDG", "dest": "JFK" },
        { "id": 3, "code": "TL345", "src": "CDG", "dest": "LYS" }
      ]
    }

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: flight-app
  namespace: apps
spec:
  replicas: 1
  selector:
    matchLabels:
      app: flight-app
  template:
    metadata:
      labels:
        app: flight-app
    spec:
      containers:
        - name: api
          image: immanuelfodor/json-server:latest
          args: ["--watch", "/api/api.json", "--static", "/public"]
          imagePullPolicy: IfNotPresent
          volumeMounts:
          - name: api-data
            mountPath: /api
          - name: openapi
            mountPath: /public
      volumes:
        - name: api-data
          configMap:
            name: flight-data
        - name: openapi
          configMap:
            name: flight-apispec

---
apiVersion: v1
kind: Service
metadata:
  name: flight-app
  namespace: apps
  labels:
    app: flight-app
spec:
  type: ClusterIP
  ports:
    - port: 3000
      name: api
  selector:
    app: flight-app

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: flight-apispec
  namespace: apps
data:
  openapi.yaml: |
    openapi: "3.0.0"
    info:
      version: 1.0.0
      title: Flights
      description: Airlines Flights API
      contact:
        name: Airlines Support
        url: 'https://example.com/'
      license:
        name: Apache 2.0
        url: 'https://spdx.org/licenses/Apache-2.0.html'
    servers:
      - url: https://api.localhost
    paths:
      /flights:
        get:
          summary: Retrieve flights
          operationId: gettFlights
          tags:
            - flights
          parameters:
            - name: limit
              in: query
              description: How many items to return at one time (max 100)
              required: false
              schema:
                type: integer
                maximum: 100
                format: int32
          responses:
            '200':
              description: A paged array of flights
              headers:
                x-next:
                  description: A link to the next page of responses
                  schema:
                    type: string
              content:
                application/json:
                  schema:
                    $ref: "#/components/schemas/Flights"
            default:
              description: unexpected error
              content:
                application/json:
                  schema:
                    $ref: "#/components/schemas/Error"
        post:
          summary: Create a flight
          operationId: createFlight
          tags:
            - flights
          responses:
            '201':
              description: Null response
            default:
              description: unexpected error
              content:
                application/json:
                  schema:
                    $ref: "#/components/schemas/Error"
      /flights/{flightId}:
        get:
          summary: Info for a specific flight
          operationId: showFlightById
          tags:
            - flights
          parameters:
            - name: flightId
              in: path
              required: true
              description: The id of the flight
              schema:
                type: string
          responses:
            '200':
              description: Expected response to a valid request
              content:
                application/json:
                  schema:
                    $ref: "#/components/schemas/Flight"
            default:
              description: unexpected error
              content:
                application/json:
                  schema:
                    $ref: "#/components/schemas/Error"
        put:
          summary: Update a flight
          operationId: updateFlight
          tags:
            - flights
          parameters:
            - name: flightId
              in: path
              required: true
              description: The id of the flight
              schema:
                type: string
          responses:
            '200':
              description: Null response
            default:
              description: unexpected error
              content:
                application/json:
                  schema:
                    $ref: "#/components/schemas/Error"
        delete:
          summary: Delete a flight
          operationId: deleteFlight
          tags:
            - flights
          parameters:
            - name: flightId
              in: path
              required: true
              description: The id of the flight
              schema:
                type: string
          responses:
            '200':
              description: Null response
            default:
              description: unexpected error
              content:
                application/json:
                  schema:
                    $ref: "#/components/schemas/Error"
    components:
      schemas:
        Flight:
          type: object
          required:
            - id
            - name
          properties:
            id:
              type: integer
              format: int64
            code:
              type: string
            source:
              type: string
            destination:
              type: string
        Flights:
          type: array
          maxItems: 100
          items:
            $ref: "#/components/schemas/Flight"
        Error:
          type: object
          required:
            - message
          properties:
            message:
              type: string

Tag summary

Content type

Image

Digest

sha256:a75e7a97d

Size

66.5 MB

Last updated

over 3 years ago

docker pull immanuelfodor/json-server