gcanahuirev / api-rest

Simple example of api rest without dependencies

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple api rest in memory

Simple test of api rest without dependencies, but in memory

  • No third-party packages/dependencies
  • You can use curl or a http client for requests

Requirements

  • Go stable version

Features

  • GET /shirts returns list of shirts as JSON
  • GET /shirts/{id} returns details of specific shirt as JSON
  • POST /shirts accepts a new shirt to be added
  • POST /shirts returns status 415 if content is not application/json
  • GET /admin requires basic auth
  • GET /shirts/random redirects (Status 302) to a random shirt

Data Types

A shirt object should look like this:

{
  "id" : "0001",
  "material" : "Lana",
  "class" : "Manga Larga",
  "size" : 14,
}

Usage

Note: If you are using pwsh, please note this

  • First configure the password, then run go run server.go
> $env:ADMIN_PASSWORD = 'secret'
  • Or just run
> ADMIN_PASSWORD='secret' go run server.go
  • To test basic authentication
> curl localhost:3000/admin -u admin:secret
  • Remember that you will have to add new data at each restart

Persistence

There is no persistence of data, a memory time is fine.

About

Simple example of api rest without dependencies


Languages

Language:Go 100.0%