Dyalog / Jarvis

APL-based web service framework supporting JSON or REST
https://dyalog.github.io/Jarvis/
MIT License
33 stars 6 forks source link

All but GET method seem to need a none empty body #61

Closed kdtp28 closed 4 months ago

kdtp28 commented 4 months ago

I created simple functions for Get, Post, Put, ... like so:

r←Get req
r←req.Endpoint

Then I issued a request from Insomnia.

For Get everything works fine. For all other methods, I need something in my request body to make it work. Otherwise jarvis ignores it.

Especially for Delete this makes no sense to me.

Help needed, Thx, Karsten

│Jarvis│1.16.3│2024-01-12│

IDE:
  Version: 4.4.3687
  Platform: MacIntel
  Date: 2022-02-23 13:44:34 +0100
  Git commit: a3d8123cfb690ead493e261ccced59407db04c64
  Preferences:{
    "colourScheme":"Dracula",
    "confirmations":"{\"SaveFileOptionsExtension:.aplf\":100,\"SaveFileOptionsExtension:.apln\":100}",
    "kbdLocale":"en_US_Mac",
    "lbarOrder":"← +-×÷*⍟⌹○!? |⌈⌊⊥⊤⊣⊢ =≠≤<>≥≡≢ ∨∧⍲⍱ ↑↓⊂⊃⊆⌷⍋⍒ ⍳⍸∊⍷∪∩~ /\\⌿⍀ ,⍪⍴⌽⊖⍉ ¨⍨.⍣∘⍤⍥@ ⍞⎕⍠⌸⌺⌶⍎⍕ ⋄⍝→⍵⍺∇& ¯⍬ ",
    "menu":"# see below for syntax\n\nDyalog                          {mac}\n  About Dyalog             =ABT\n  -\n  Preferences...           =PRF\n  -                            \n  &Quit                    =QIT\n&File                           {!browser}\n  &Open...                 =OWS {local}\n  &New Session             =NEW\n  &Connect...              =CNC\n  -                             {!mac}\n  &Quit                    =QIT {!mac}\n&Edit\n  Undo                     =UND {!browser}\n  Redo                     =RDO {!browser}\n  -                             {!browser}\n  Cut                      =CT  {!browser}\n  Copy                     =CP  {!browser}\n  Paste                    =PT  {!browser}\n  Select All               =SA  {mac}\n  -                             {mac||!browser}\n  &Find...                 =SC\n  Find and &Replace...     =RP\n  -                             {!mac}\n  Preferences...           =PRF {!mac}\n&View\n  Show Language Bar        =LBR\n  Show Status Bar          =SBR\n  Show Workspace Explorer  =WSE\n  Show Debug               =DBG\n  Line Wrapping in Session =WRP\n  -                             {!browser}\n  Show Status Window       =SSW\n  Auto Status              =ASW\n  -                             {!browser}\n  Stops                    =TVB\n  Line Numbers             =LN\n  Outline                  =TVO\n  -                             {!browser}\n  Increase Font Size       =ZMI {!browser}\n  Decrease Font Size       =ZMO {!browser}\n  Reset Font Size          =ZMR {!browser}\n  -                             {!browser}\n  Toggle Full Screen            {!browser}\n&Window\n  Close All Windows        =CAW\n&Action\n  Edit                     =ED\n  Trace                    =TC\n  -\n  Clear all trace/stop/monitor =CAM\n  Weak Interrupt           =WI\n  Strong Interrupt         =SI\n&Threads                        {rp21}\n  Pause on Error           =POE\n  Pause all Threads        =PAT\n  Unpause all threads      =UAT\n  Continue all threads     =MA\n&My\n  Dyalog\n    Mastering APL          =https://mastering.dyalog.com/README.html\n  -\n  APL Cart                 =https://aplcart.info\n  APL Wiki                 =https://aplwiki.com\n&Help\n  Getting &Started         =https://dyalog.com/introduction.htm\n  -\n  Dyalog &Help             =DHI\n  &Language Elements       =LEL\n  &Documentation Centre    =DOX\n  -\n  Dyalog &Website          =https://dyalog.com/\n  &Email Dyalog            =EMD\n  -\n  Latest &Enhancements     =ENH\n  Read &Me                 =RME\n  &Third Party Licences    =TPL\n  &About                   =ABT {!mac}\n\n# Syntax:\n#   &x   access key, alt+x\n#   =CMD command code; some are special:\n#          LBR WRP WSE render as checkboxes\n#   =http://example.com/  open a URL\n#   {}   conditional display, a boolean expression\n#          operators: && || ! ( )\n#          variables: local browser mac win\n#   -    separator (when alone)\n#   #    comment\n\n# The =PRF (\"Preferences...\") menu item must be present.",
    "otherExe":"/Applications/Dyalog-18.2.app/Contents/Resources/app/../Dyalog/mapl",
    "wse":"1",
    "zoom":"3"
  }

Interpreter:
  Version: 18.2.45505
  Platform: Mac-64
  Edition: Unicode/64
  Date: Apr  7 2022 at 00:12:12
bpbecker commented 4 months ago

Hi Karsten,

Thanks for reporting this issue. However, I'm not able to reproduce the behavior you describe.

      j←Jarvis.New ''   ⍝ create a new Jarvis server
      j.Paradigm←'REST' ⍝ set the Paradigm

⍝ now define some endpoints
      Get←{⍵.(Method Endpoint Body)}
      Post←{⍵.(Method Endpoint Body)}
      Delete←{⍵.(Method Endpoint Body)}

      j.Start
Start[3] 2024-02-08 @ 12.53.33.486 - Starting  Jarvis  1.16.3 
LoadConga[32] 2024-02-08 @ 12.53.33.501 - Conga copied from C:\Program Files\Dyalog\Dyalog APL-64 18.2 Unicode/ws/conga
LoadConga[44] 2024-02-08 @ 12.53.33.501 - Local Conga v4.3 reference is #.Jarvis.[LIB]
Start[83] 2024-02-08 @ 12.53.33.517 - Jarvis starting in "REST" mode on port 8080
Start[84] 2024-02-08 @ 12.53.33.520 - Serving code in #
0  Server started 

⍝ I use HttpCommand to test
      h←HttpCommand.New ''
      h.BaseURL←'localhost:8080'
      h.(Command URL)←'Get' 'getme'

      h.Show
GET /getme HTTP/1.1                                                    
Host: localhost:8080                
User-Agent: Dyalog-HttpCommand/5.4.4
Accept: */*                         
Accept-Encoding: gzip, deflate      

      h.Run.Data ⍝ run it and return the response payload
["get","/getme",""]

      h.(Command URL)←'post' 'postme' ⍝ now try POST
      h.Run.Data
["post","/postme",""]

      h.(Command URL)←'delete' 'deleteme' ⍝ now try DELETE
      h.Run.Data
["delete","/deleteme",""]

Have you verified that Jarvis is getting the requests? You can set Debug←2 on the Jarvis instance and it will stop just prior to calling any of your code.

I hope this helps! /Brian

bpbecker commented 4 months ago

Fixed in a02f51491ed5808f4219b37cc82836162944dd83 (release v1.17.0).

This was an interesting issue. Because of the discrepancy in behavior between what Karsten was seeing with Insomnia and what I was seeing using HttpCommand, I decided to investigate further and installed Insomnia. There is a subtle difference in behavior between the two:

Jarvis was not picking up on the "content-length: 0" header and as such was expecting an HTTPBody event, which never came, and so the system seemed to hang.

kdtp commented 4 months ago

Thanks a lot. Good work. That was all a needed.

I dived a little bit into the http protocol and found the following: https://www.rfc-editor.org/rfc/rfc7230#section-3.3.3 Especially starting with Point 4, it becomes more complicated.

Karsten