Giter Club home page Giter Club logo

Comments (3)

bpbecker avatar bpbecker commented on June 7, 2024

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.

arcfide avatar arcfide commented on June 7, 2024

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.

bpbecker avatar bpbecker commented on June 7, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.