BackPack: A DSL for REST APIs

Eric Jhon Jumaday

Compiler Design
Software Architect
Software Engineer
Rust
BackPack is a domain-specific language (DSL) designed to simplify the creation of REST APIs. While it retains familiar constructs such as variables, functions, and classes, BackPack introduces a unique feature: methods. Methods in BackPack are special functions that are tied to HTTP request types (e.g., GET, POST, PUT, etc.). These methods can only be invoked through external HTTP requests, whereas regular functions can only be called within the program itself.
The syntax and structure of BackPack are designed to be intuitive for developers familiar with web APIs and server-side programming. The method declarations are simple and concise, allowing developers to focus on defining API behavior without having to worry about underlying HTTP mechanics.

Key Features:

Methods: Methods in BackPack are defined using HTTP request types as keywords (e.g., GET, POST, PUT, DELETE). These methods are intended to handle external HTTP requests and generate responses.
Functions: Functions in BackPack, like in most programming languages, are used for internal program logic and cannot be triggered by HTTP requests.
Seamless Integration: BackPack allows seamless integration with RESTful services, making it easy to handle common API actions like authentication, data retrieval, and error handling.
Built-in HTTP Response Handling: The language includes simple constructs for responding with standard HTTP status codes and messages.

Example Code:

example code of BackPack
example code of BackPack

Explanation:

GET hello: This is a method tied to a GET HTTP request. It sends a simple "Hello! from BackPack" response with an HTTP 200 OK status.
POST /auth/login: This method listens for a POST request on the /auth/login endpoint. It expects a JSON body with username and password fields. If the authentication fails, it responds with a 401 Unauthorized status. If the login is successful, it generates a token and responds with a 200 OK status and a JSON object containing the success message and token.

How BackPack Works:

Methods are externally triggered by HTTP requests (e.g., GET, POST).
Functions perform internal logic and calculations but are not exposed to external HTTP calls.
BackPack abstracts the common patterns of API development, providing a concise and efficient way to define API endpoints and handle HTTP responses.

Use Cases:

BackPack is ideal for:
Rapid API prototyping
Simplifying server-side logic for RESTful services
Creating small to medium-sized REST APIs with minimal boilerplate code
This approach empowers developers to focus on business logic while BackPack handles the HTTP intricacies.
Partner With Eric Jhon
View Services

More Projects by Eric Jhon