Sign in Join

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

Catalog · How the catalog works
Anything · Lazarus or Delphi
Random projectRandom project

REST-API-server-in-FreePascal

View on GitHub

Member rating

No ratings yet.

Sign in to rate this project.

README

Pascal REST API — Todo App

A minimal REST API written in FreePascal using the Horse web framework.

Features

  • Full CRUD for a Todo resource
  • JSON request/response
  • In-memory storage (easy to swap for a DB)
  • Runs on port 9000

Requirements

Install Horse

Using the Online Package Manager in Lazarus:

  1. Open Lazarus → Package → Online Package Manager
  2. Search for Horse and install it

Or manually clone it:

bash
git clone https://github.com/HashLoad/horse.git

Then add the Horse source path to your project's compiler options.

Build & Run

With Lazarus:

  1. Open pascal-rest-api.lpi
  2. Press F9 to compile and run

With FPC directly:

bash
fpc server.pas
./server

API Endpoints

Method Endpoint Description
GET /todos List all todos
GET /todos/:id Get one todo
POST /todos Create a todo
PUT /todos/:id Update a todo
DELETE /todos/:id Delete a todo

Example Requests

bash
# List all
curl http://localhost:9000/todos

# Create
curl -X POST http://localhost:9000/todos \
  -H "Content-Type: application/json" \
  -d '{"title": "Buy milk"}'

# Update
curl -X PUT http://localhost:9000/todos/1 \
  -H "Content-Type: application/json" \
  -d '{"done": true}'

# Delete
curl -X DELETE http://localhost:9000/todos/1

Project Structure

pascal
pascal-rest-api/
????????? server.pas          # Entry point
????????? models.todo.pas     # Todo model + in-memory store
????????? routes.todos.pas    # Route handlers
????????? pascal-rest-api.lpi # Lazarus project file
????????? README.md

License

MIT