Comments (3)
Currently MiPages produce only HTML. There's a lot of integral infrastructure that automates the rendering of the html, head, and body elements to alleviate the user having to manage them. For instance, the Add method in a MiPage looks at what's being added and determines whether it belongs in the head or body element.
Non-HTML MIME types are supported by requesting files with extensions other than .mipage, in which case we attempt to look up the appropriate setting for 'content-type' based on the file's extension. But that requires the content to be in a file.
I assume you're asking for this because you want to generate the content on the fly? Otherwise, writing the data to file and making a request for the file rather than a MiPage would work.
I can see a way to make this work with relatively little modification.
:Class index : #.MiPage
∇ Compose
:Access public
_Request.SetContentType '.json' ⍝ or 'content-type' _Request.SetHeader 'application/json'
Add ⎕JSON ⍳10
∇ Compose
:EndClass
Then MiServer could detect if the content-type header has been set and if it's not text/html, then we render the contents of the body element, but not wrap them in the HTML tag.
I can see one other way to make this work without any modification to MiServer. Basically, generate your content, write it to file, and make the rendered MiPage load the file. Of course, you'd then need to manage cleaning up the files you wrote, but that's not terribly complicated.
:Class index : #.MiPage
∇ Compose
:Access public
OnLoad←'window.location.href="data.json"'
(⎕JSON⍳10)⎕NPUT(#.Boot.AppRoot,'data.json')1
∇
:EndClass
Let me know if the latter solution works for you.
from miserver.
I can see a way to make this work with relatively little modification.
Are you saying that this is not implemented yet? I do need to dynamically generate the files, so just referencing a file will not work. I can potentially generate files and then link to them, but that might introduce race conditions in certain workloads, so it would be nice to be able to do this without being forced to go to the filesystem.
I will give the filesystem approach a try, but if the first approach is implemented, that seems like a better one.
from miserver.
That's right. MiServer was initially designed as a means for users to:
- host their applications on the web
- provide a GUI on non-Windows platforms
- have one code base to deliver their applications cross-platform.
without needing extensive knowledge about HTML, CSS, etc. So, the MiPage class, which is based on HtmlPage, which is based on HtmlElement was always intended to serve HTML content.
However, having said that, I just remembered that when I implemented RESTful support for MiServer, I created another page template, RESTfulPage, that should work for you...
Instead of a Compose method, RESTfulPage requires a Respond method which returns the content to be sent back to the client. By default, you can return APL data and MiServer will convert it to JSON format, flattening any arrays of rank>1.
:Class index : #.RESTfulPage
∇ r←Respond
:Access public
r←3 3⍴⍳9
∇
:EndClass
will return
[[1,2,3],[4,5,6],[7,8,9]]
You can also set the content-type and return whatever you want.
:Class index : #.RESTfulPage
∇ r←Respond
:Access public
SetContentType'text/csv'
r←'"Drake","Mallard",42',(⎕UCS 10),'"Mickey","Mouse",107'
∇
:EndClass
I think this should meet your needs?
I made a couple of minor changes so you should pull the 04a37e5 commit or later.
from miserver.
Related Issues (20)
- What to do when there's a rendering problem? HOT 4
- DrA Directory is wrong HOT 1
- Samples -> Accordion which calls back to the server on open/close fails
- Links open in a new window
- MiServer gets closed socket when querying with cURL HOT 1
- Starting MS3 sample site fails when MiServer is installed into a directory with spaces in the directory path HOT 6
- MiServer 3.0.1539 Compose vs Render and _Request.GetData HOT 2
- No 404 Page Response? HOT 6
- How to Debug MiServer Crash? HOT 1
- ListManager places blank item at top of list
- DOMAIN ERROR: Base class for Class "Page" has not been resolved
- UtcOffset is never refreshed
- Clicking APL expressions in the Idiom Search does not copy to clipboard
- Using curl seems to never free up workspace leading to WS FULLs HOT 1
- Linux (ubuntu 16.04): get "SQA failed to initialize" when starting sample misite HOT 1
- Should always attempt to ⎕CY'conga' as a fallback if a more specific location fails
- Configuration timeouts - 0 default doesn't work
- fix DC.Select for HTML5 form validation
- miserver.dyalog.com links to a branch that is 404
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from miserver.