Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

lazy-rest

LazyREST is a quick HTTP(s) web server that will accept JSON data for any simple endpoint. It stores data in flat JSON files to allow quick setup for mock and testing environments.

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

LazyREST

logo

LazyREST is a quick HTTP(s) web server that will accept JSON data for any simple endpoint. It stores data in flat JSON files to allow quick setup for mock and testing environments.

image

For example

  • https://localhost:14544/json
  • https://localhost:14544/customer
  • https://localhost:14544/delphirocks

Postman samples are included in the installation or source

Web pages can also be served by placing them into the HTML folder.

A default template modified from HTML5UP has been provided.

Icons are from Icons8

Post

  • https://localhost:14544/json?validatejson=false
  • https://localhost:14544/json?validatejson=true&id=123
  • https://localhost:14544/json

Body should contain valid JSON. The server has a global Validate JSON option but you can also toggle on each call.

pascal
{
 "firstName": "Mary",
 "lastName": "Jane"
}

The REST endpoint will generate a GUID your data is stored into and respond with the ID or an ID can be forced with the id parameter

pascal
{
    "id": "123"
}

Put

  • https://localhost:14544/json/A90F3635-DFC7-4BA9-BB65-08C9BCAFA894
  • https://localhost:14544/json/123

Body should contain valid JSON eg

pascal
{
 "firstName": "Mary",
 "lastName": "Jane"
}

A PUT request will update and existing entry or create a new entry with the specified ID. The response will be the ID

pascal
{
    "id": "123"
}

Get

  • https://localhost:14544/json?limit=3&offset=2&search=Mary
  • https://localhost:14544/json/04F8E7F8-4BE4-42EE-971B-66E8EF44CE80
  • https://localhost:14544/json/123

Get supports simple text searching as well as a limit and offset to allow simple pagination

pascal
[
 {
  "firstName": "Mary",
  "lastName": "Jane"
 },
 {
  "firstName": "Fred",
  "lastName": "Bloggs"
 }
]

Delete

  • https://localhost:14544/json/A90F3635-DFC7-4BA9-BB65-08C9BCAFA894?softdelete=true
  • https://localhost:14544/json/A90F3635-DFC7-4BA9-BB65-08C9BCAFA894
  • https://localhost:14544/json
  • https://localhost:14544/json?softdelete=true

Delete can delete a specific entry or all entries. The softdelete parameter will just rename the file from .json to .del to allow quick restoration of a record. The response will be the ID or list of ID's deleted.

pascal
[
{
"ID": "04F8E7F8-4BE4-42EE-971B-66E8EF44CE80"
},
{
"ID": "123"
},
{
"ID": "3F686925-672F-44A9-925C-BA7743DF0D8F"
},
{
"ID": "443A668F-DF83-4B2D-B3D4-B151E59F3E37"
}
]

Use Cases

Prototype

Prototype a Web or Firemonkey mobile application and make it actually work with simple REST endpoints but no need for schema or database

Data Gathering

Submitted PC details via powershell to quickly generate a report on makes and model

pascal
$url = "http://localhost:14544/pcdata"
$url = "$url/$id"
Write-Host "Status: Submitting PC details to $url"
try {
$result = Invoke-WebRequest -Uri $url -ContentType "application/json" -Method PUT -Body $json 
if ($result.StatusCode -eq 200) {
Write-Host "Success: Data has been submitted for PC id $id"
} else {
Write-Host $result.StatusDescription
}
} catch {
  Write-Host "Failed: Failed to submit data, error: $_"
}

Compiling

Delphi 10.4 is the current target version for compilation

Components