Skip to main content
squid·ware

Package · Hello World

GET /

Returns a JSON greeting message.

Endpoint

NameValue
No query parameters

Responses

StatusDescription
200Request was successful
{
  "message": "Hello, World!"
}
400Bad request
401Unauthorized
403Forbidden
404Not found
500Internal server error

Architecture Decision Records

  • The API returns a JSON object containing a greeting message.
  • The API is designed to be simple and easy to understand, making it a good starting point for learning how to build APIs.

Request Overview

Client Hello World API GET Request 200 OK JSON Response

Implementation

package main

import (
	"encoding/json"
	"net/http"
)

func main() {
    http.HandleFunc("/", helloWorldHandler)
    http.ListenAndServe(":8080", nil)
}

func helloWorldHandler(w http.ResponseWriter, r *http.Request) {
    // Set the Content-Type header to application/json
    w.Header().Set("Content-Type", "application/json")
    
    // Create a map for the JSON response
    response := map[string]string{"message": "Hello, World!"}
    
    // Encode the map as JSON and write it to the response
    json.NewEncoder(w).Encode(response)
}

hello-world.go

Contract

{
  "openapi": "3.0.3",
  "info": {
    "title": "Hello World API",
    "version": "1.0.0",
    "description": "A simple example API that returns a greeting message."
  },
  "servers": [
    {
      "url": "https://hello-world.api.docs.squid-ware.nl"
    }
  ],
  "paths": {
    "/": {
      "get": {
        "operationId": "getHelloWorld",
        "summary": "Get greeting",
        "description": "Returns a JSON object containing a greeting message.",
        "responses": {
          "200": {
            "description": "Greeting response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["message"],
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "Hello, World!"
                    }
                  }
                },
                "example": {
                  "message": "Hello, World!"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {}
}

hello-world.contract.json