Skip to content

azapater/sqids-radserver

Repository files navigation

Sqids & RAD Server for Delphi

Sqids Screen Shot

Sqids (pronounced "squids") is a small library that lets you generate unique IDs from numbers. It's good for link shortening, fast & URL-safe ID generation and decoding back into numbers for quicker database lookups.

Features:

  • Encode multiple numbers - generate short IDs from one or several non-negative numbers
  • Quick decoding - easily decode IDs back into numbers
  • Unique IDs - generate unique IDs by shuffling the alphabet once
  • ID padding - provide minimum length to make IDs more uniform
  • URL safe - auto-generated IDs do not contain common profanity
  • Randomized output - Sequential input provides nonconsecutive IDs
  • Many implementations - Support for 40+ programming languages

Use-cases

✅ Good for:

  • Generating IDs for public URLs (eg: link shortening)
  • Generating IDs for internal systems (eg: event tracking)
  • Decoding for quicker database lookups (eg: by primary keys)

❌ Not good for:

  • Sensitive data (this is not an encryption library)
  • User IDs (can be decoded revealing user count)

About this repository

This respository contains a ProjectGroup with two Delphi projects. One is the RAD Server instance and a VCL client that connects to it. Becuase this demo connects to a database, you will need to define in the FDConnection the InterBase employee.gdb database.

Sqids Code examples with RAD Server

RAD Server integrates Sqids since RAD Studio 12 Athens. To encode and decode your IDs you only need to define in the TRESTRequest.Resource the symbol # before the ID.

Using the TEMSDatasetResource attributes

[ResourceName('Customers')]
TCustomersResource = class(TDataModule)
  qryCustomers: TFDQuery;
  [ResourceSuffix('list', '/')]
  [ResourceSuffix('get', '/{#CUST_NO}')]
  [ResourceSuffix('put', '/{#CUST_NO}')]
  [ResourceSuffix('post', '/')]
  [ResourceSuffix('delete', '/{#CUST_NO}')]
  resCustomers: TEMSDataSetResource;
  FDConnection1: TFDConnection;
end;

Changing the default alphabet and length on RADServer.ini

[Server.Sqids]
;# The following options control URL parameters Sqids decoding
;#
;# Optional alphabet for Sqids decoding
Alphabet=
;# Optional minimal hash length for Sqids decoding
MinHashLength=0

Connecting to a RAD Server instance using Sqids

Using the component EMSServer properties allows to define the Alphabet and MinHashLength defined in RAD Server. To specify which endpoints are encoded it requires to specify it in the TRESTRequest.Resource.

BackendEndpoint1.ResourceSuffix := '/{#CUST_NO}';

Prerequisites

For compiling this project you will need:

  • Delphi 12 Athens+
  • InterBase 2020+ with the employee.gdb database

Clone the repo

git clone https://github.com/azapater/sqids-radserver.git

Contact

Repo Link: https://github.com/azapater/sqids-radserver

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages