Skip to content

Releases: iyifr/h4

v0.4.6

15 Jul 16:13

Choose a tag to compare

0.4.6

  • Refactored readRequestBody utility, making it more efficient and less error prone.
  • Made readRequestBody utility generic for better typing, but didn't get very far using native types.
  • Added more tests for the readRequestBody utility.

The utility can now also handle FormData request bodies, but it is recommended to use readFormData or readFiles for the standard way of reading other data types from the request body.

The utility was also made generic for stronger typing but avoid using specific types directly e.g

// Will throw type error because casting doesn't work for complex types
List<Map<String, User>>? body = readRequestBody(event)

// Preferred
// You can then use a class to improve the type or use `fromJson` helpers
List<Map<String, dynamic>>? body = readRequestBody(event)

v.0.4.4 (Patch)

28 Feb 10:53

Choose a tag to compare

  • OPTIMIZED Router implementation:

    • Improved root path ('/') handling
    • Simplified conditional logic in route handler with ternary expressions
    • Removed support for '**' wildcard pattern
  • IMPROVED Test coverage:

    • Added test for named routes
    • Simplified wildcard route tests by removing redundant assertions
    • Removed unnecessary status code checks
  • REFACTORED Internal code:

    • Streamlined error handling logic in router
    • Improved code readability with more concise syntax

v0.4.3 (Patch Release)

05 Feb 22:13

Choose a tag to compare

0.4.3 (Patch Release)

  • IMPROVED CORS handling with new handleCors utility:

    • Added support for credentials, max age, and custom headers
    • Better documentation and examples for CORS configuration
    • Default values for common CORS scenarios
  • ENHANCED IP address detection in getRequestIp:

    • Added support for additional IP headers:
      • X-Real-IP
      • CF-Connecting-IP
      • True-Client-IP
    • Improved fallback chain for IP detection
  • OPTIMIZED Router implementation:

    • Improved param route scanning efficiency
    • Better handling of root path ('/')
    • Removed unused root handler parameter
  • IMPROVED Documentation:

    • Added comprehensive examples for route parameters
    • Enhanced documentation for request utilities
    • Updated contributing guidelines
  • REFACTORED Internal utilities:

    • Moved multipart form handling to private methods
    • Better organization of request utilities
    • Improved code readability and maintainability

v0.4.2

19 Jan 11:56

Choose a tag to compare

0.4.2 (Patch Release)

  • EXTENDED readFiles utility with new options for file handling:
    • Added hashFileName parameter (boolean) to control file name generation
    • Added maxFileSize parameter (int, MB) to limit upload sizes
    • Default values: hashFileName: false, maxFileSize: 10
  • IMPROVED Documentation for file upload functionality in README
  • UPDATED Documentation comments for readFiles utility with comprehensive examples and return
    type details

v0.4.0

12 Dec 08:46

Choose a tag to compare

0.4.0 (Minor)

  • NEW readFiles utility to handle file uploads.
var files = await readFiles(event, fieldName: 'file', customFilePath: 'uploads');
// files is a List<Map<String, dynamic>> containing the info of the files uploaded.
// Example:
// [
//   {
//     'path': 'uploads/test.txt',
//     'mimeType': 'text/plain',
//     'originalname': 'test.txt',
//     'fieldName': 'file',
//     'size': 17,
//     'tempFilename': 'test.txt'
//   }
// ]

// EXAMPLE HANDLER.
router.post("/upload", (event) async {
  var files = await readFiles(event, fieldName: 'file', customFilePath: 'uploads');
  return files;
});
  • PATCHED readFiles utility to handle file uploads better.

Full Changelog: v0.3.2...v0.4.0

Full Changelog: v0.3.2...v0.4.0

v0.3.2 (Patch CLI)

08 Dec 21:27

Choose a tag to compare

Patch Bug in CLI when you try to boostrap an APP and the name of your app has a _ in it's string.

v0.3.1

08 Oct 20:01

Choose a tag to compare

0.3.1 (Patch)

  • EXTENDED readFormData utility to handle undefined formdata fields better.
  • PATCHED setResponseHeader utility to better handle immutable nature of http response
    headers.
  • Documented some utilities better.
  • Entire library is now accessible from one import.

v0.3.0

02 Sep 00:51

Choose a tag to compare

  • NEW Multiple Routers with basePath
void main() async {
  var app = createApp(
    port: 5173,
    onRequest: (event) {
      // PER REQUEST local state😻
      event.context["user"] = 'Ogunlepon';

      setResponseHeader(event,
          header: HttpHeaders.contentTypeHeader,
          value: 'text/html; charset=utf-8');
    },
    afterResponse: (event) => {},
  );

  var router = createRouter();
  var apiRouter = createRouter();

  app.use(router, basePath: '/');
  app.use(apiRouter, basePath: '/api');

  router.get("/vamos/:id/base/:studentId", (event) {
    return event.params;
  });

  apiRouter.get("/signup", (event) async {
    var formData = await readFormData(event);

    var username = formData.get('username');
    var password = formData.get('password');

    // userService.signup(username, password);
    event.statusCode = 201;

    return 'Hi from /api with $username, $password';
  });
}
  • NEW readFormData utility - familiar formdata parsing API
apiRouter.get("/signup", (event) async  {
  var formData = await readFormData(event);

  var username = formData.get('username');
  var password = formData.get('password');

  // ALSO included..
  var allNames = formdata.getAll('names') // return List<String>

  userService.signup(username, password);
  event.statusCode = 201;

  return 'Hi from /api';
});
  • NEW getRequestIp and getRequestOrigin utilities

  • PATCHED H4Event params now correctly parses more than one param in the route string. e.g
    '/user/:userId/profile/:projectId'

  • PATCHED all bugs in the behaviour of param routes.

  • PATCHED getRequestHeader utility

v0.2.0

30 Aug 10:46

Choose a tag to compare

0.2.0

  • Minor Release

    • Improved CLI

      • Added a new command H4 start which starts your app locally.
      h4 start

      or

      dart pub global run h4:start

      --dev flag

      • Run the command with the --dev flag to restart the server when you make changes to your files
    • New Utilities

      • getQuery
      • setResponseHeader
      • getHeader

v0.1.4

29 Aug 13:02

Choose a tag to compare

0.1.4

  • H4 CLI.

    • Added a basic CLI that bootstraps a H4 app

      • The H4 init command bootstraps a full H4 app.
      dart pub global activate h4

      then run

      h4 init

      or

      dart pub global run h4:init
    • Removed compute dependency