Options
All
  • Public
  • Public/Protected
  • All
Menu
     

Interface Doc

Config properties a Route's Documentation.

Hierarchy

  • Doc

Index

Properties

Optional Headers

Headers: CLHeaders

A collection of Header GNDescr objects.

Optional Files

Files: object

When an EndPoint requires the ability to upload files, this object tells the internal Upload-Handler how to upload the files.

IMPORTANT: Upload request must be called as a POST, PUT, or DELETE method.

Uploading with dffrnt.api

The system will handle the middleware required to process an upload request, so long as the request-method definition includes this Files object.

During an upload, dffrnt.api goes through 3 phases:

  • The internal upload-middleware detects if the Files.field you've defined contains any filenames.
  • It will then proceed to process the file(s) into Streams, and gather any meta-data. Only first Files.max(n) files--if set--will be processed.
  • From here, it passed the path/body params and meta-data to the Files.dest Files.name callbacks to determine where, and under what name the file(s) should be saved.
  • Lastly, the Files.field param, and a private location param will be set on the requests body which is then passed to your request-method Query function so the upload can be logged in your database or whatever post-processing you need done.

Uploads are always stored in <project_root>/storage/*; however, this object allows you to define which folders within <project_root>/storage/* the files will go to, how the files will be named, etc.

Type declaration

  • field: string

    The name of the GNParam that represents the <file> element or files list in the request.

    Example

    index.html:

    <form method="POST" action="...">
        <input type="file" name="upload" />
    </form>

    config/endpoints.cfg.js:

    {   // curl -X POST https://host/point -d "username=coolguy" ...
        field: 'upload',
    }   // File is saved to <project_root>/storage/coolguy/*
  • Optional max?: number

    An optional maximum amount of files that can be pushed to this request. A client can still request more than the max if the Browser Application allows for it, but the internal uploader will only upload the first max(n) files that show up in the filename list.

  • dest: function
    • An optional callback you can define to determine--based on the parameters it sets--where in the <project_root>/storage/ folder the file(s) will be saved.

      If not defined, any files sent will be saved as <project_root>/storage/<filename>.

      Example

      {   // curl -X POST https://host/point -d "username=coolguy" ...
          dest(prm, bdy, file) { return bdy.username; },
      }   // File is saved to <project_root>/storage/coolguy/*

      Parameters

      • prm: TPQryObject

        The path-params sent with the request.

      • bdy: TPQryObject

        The body-params sent with the request.

      • file: File

        An object of meta-data retrieved from the uploaded file(s).

      Returns string

  • name: function
    • An optional callback you can define to determine--based on the parameters it sets--what name(s) the file(s) will be saved under.

      If not defined, any files sent will be saved as <project_root>/storage(/<destination>)/<originalName>.

      Example

      {   // curl -X POST https://host/point/12345" ...
          dest(prm, bdy, file) { return 'profile_pics'; },
          name(prm, bdy, file) { return prm.user_id; }, // <---
      }   // File is saved as <project_root>/storage/profile_pics/12345.jpg

      Parameters

      • prm: TPQryObject

        The path-params sent with the request.

      • bdy: TPQryObject

        The body-params sent with the request.

      • file: File

        An object of meta-data retrieved from the uploaded file(s).

      Returns string

Optional Examples

Examples: object

A collection of Query Examples.

Type declaration

  • [exampleName: string]: string

Optional Params

Params: CLParams

A collection of GNParam objects (for <a href="../classes/_dffrnt_confs.routeau.html">RouteAU_).