Better access to request/response objects

I guess I’m hoping for better/easier access to request/response objects

I dont want to call it ‘page request’ as api reponse isn’t a page, and as we serve more and more api requests alongside html requests, a more generic approach needs to be looked at.

It would be great to be able to more easily set values for headers, status, content body etc without having to wire this into a framework (the less overhead the better), even if these are simply helper functions it makes sense as we have handles on cookies and other things, to have a service/factory/something to manage request and response object.

Would also be great to have a “beforeResponseReturn” and “beforeRequestStart” event triggers also so that data protection and data security layers could be run ( potentially server wide from server.cfc ) giving lucee an extra cool set of security events that utilities like fuseguard and other inhouse opsec systems could hook into.

Basically looking for more page lifecycle handles CFML style easy abstractions.

header.setAccessControl("Allow-Origin","GET, POST, PUT, DELETE, OPTIONS')
header.setAllowMethods('GET, POST, PUT, DELETE, OPTIONS')

content.setBody('<html></html>');
content.setType('application/json');

header.setAuthorization('Bearer #token#');
header.setStatus(200) or context.set(200,"OK Bro")
header.exposeHeaders('Content-Type, Authorization')

#discuss

1 Like

FW/1 gives you all this with minimum overhead. Have you tried that?
See https://framework-one.github.io/ or also GitHub - framework-one/fw1: FW/1 - Framework One - is a lightweight, convention over configuration, MVC application framework for ColdFusion / CFML.

1 Like

Hey dawesi,

Nothing against FW/1, but by using an Application.cfc file you can build your own framework.

The key life cycle events are onRequestStart, onRequest, and onRequestEnd.

For example, setting global variables, declare the response as a variable, and apply that response to a layout

You can also create your own BIFs such as…

html = (returnDoc) => {
cfcontent(type=“text/html”);
return writeoutput(returnDoc);
};

Hope that helps.

1 Like

already using a framework that has something similar to fw/1

Fun fact: teamcfml framework (back then called diimes) was released in same timeframe as fw/1 with similar design concept (at the time).

I was hoping for lucee to adopt this so we could write less code to get to common values.

sometimes i just want to get or set something with 10 lines of code in an app without a framework.

Like a rest router with 50 lines of code delivering a static file output, i just want pure bare metal speed, no overheads and super simple code.

Most of your examples can already be achieved using

and it’s lighter weight counterpart (it’s doesn’t reparse the entire request, just the headers)

Beyond that, a lot of what your are describing is provided by the existing REST support

We added support for multiple REST METHODS in 6.1
https://luceeserver.atlassian.net/browse/LDEV-4861

If there are some additional underlying functionality required, let me know

1 Like

can we lose the cf prefix on functions in 7.0? (or have both prefix or not?)

eg; cfheader

Asking for a friend :wink:

Also can you add Azure Key vault to list of providers your looking to integrate ( you have aws/google/docker)…

Key Vault | Microsoft Azure

cfheader is a tag

tags in script and as functions have been already around for long time?

header name='Expires'       value='#getHttpTimeString( now() + 10 )#';
cfheader(statuscode="404" statustext="Invalid access");

yes, yes, I know that horrific syntax is available. #headinhands #rocksbackwardandforward

1 Like