havlu

command module
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2024 License: MIT Imports: 17 Imported by: 0

README

havlu

Havlu lets you focus on the frontend by making it effortless to have a custom REST. You give the JSON, it gives you the REST API. Fast, easy, and reliable. You can self-host it, easily deploy it to somewhere, or use it as a Docker container. Everything happening on the memory, so you don't need to worry about the database.

Motivation

When you are developing a frontend application, you need a backend to serve your data. You can use a mock server, but it is not always enough. You may need to have a custom REST API. Havlu is a tool that helps you to create a custom REST API with a JSON file.

However, havlu is not offering a new approach for existing tools like json-server. It does the same thing but faster. Why not?

Installation

Mac OS

brew install fdemir/tap/havlu

Go

go install github.com/fdemir/havlu@latest

Source

git clone
cd havlu
go install

Usage

havlu data.json --port 3000

Options

Option Description Default
--port Port number 3000
--host Host name localhost
--cors Enable CORS false
--delay Response delay in milliseconds 0
--help Show help
--version Show version number

Hav File

Hav is a simple schema file that defines the entities(resources) and their fake data types. It helps you create mock APIs faster. Here is an example:

example.hav

entity user {
  name Person.Name
  email Internet.Email
}

entity address {
  lat Address.Latitude
  lon Address.Longitude
}

It uses Faker under the hood. You can use the any available methods as a data type. Like the following Person.Name or Address.Latitude.

JSON File

The JSON file should be an array of objects. Each object represents a resource. The key of the object is the resource name. The value of the object is an array of objects. Each object represents a resource item. The key of the object is the resource item id. The value of the object is the resource item.

db.json

[
  {
    "users": [
      {
        "id": 1,
        "name": "Furkan Demir",
        "gender": "G",
      },
      {
        "id": 2,
        "name": "John Doe",
        "gender": "B"
      }
    ]
  }
]

Run havlu with the following command.

havlu db.json

It will create a REST API for the users resource.

GET    /users
POST /users
DELETE /users/:id
GET /users?field=value

Using as Module

You can adapt havlu to your own server by using it as a module.

todo!

License

MIT

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL