Pragmas seem to work differently than I expect in Primorsky

Quite unexpectedly for Pharo / Seaside, and I haven't used Smalltalk for a long time. I am trying to make a RESTful service and cannot get it to work using pragmas as it seems to me. Those. here is my list method in the TeamMembers class which is a direct subclass of WARestfulHandler.

list
   <get>

^ String streamContents: [ :stream |
    self teamMembers do: [ :each |
       stream nextPutAll: each ; crlf ] ]

      

After fully registering WAAdmin register: TeamMembers at: 'team-members' when I execute in browser ( http: // localhost: 8080 / team-members ) I got the message

/ team members not found
but if I execute ( http: // localhost: 8080 / team-members / list ) it works as expected.

This seems to contradict the documentation at http://book.seaside.st/book/advanced/restful/getting-started/define-handler .

If I override TeamMembers ->

createRoutes
    | route |
    route := WARoute get: '/listJson' selector: #listJson.
    ^OrderedCollection new
        "GET"
        add: route; 
        add: (WARoute get: #list); 
        yourself

      

Then I get the expected behavior when browsing ( http: // localhost: 8080 / team-members )

However, in order to get Json output, I still have to use ( http: // localhost: 8080 / team-members / listJson ).

I probably missed something pretty simple, but any help is appreciated.

Using Pharo6.0-64.image with Seaside and this is how the seaside was established.

Metacello new
  configuration:'Seaside3';
  repository: 
 'http://www.smalltalkhub.com/mc/Seaside/MetacelloConfigurations/main';
  version: #stable;
  load.


Gofer new
  squeaksource: 'Seaside30Addons';
  package: 'Seaside-REST-Core';
  package: 'Seaside-Pharo-REST-Core';
  package: 'Seaside-Tests-REST-Core';
  load.

      

thank

+3


source to share


2 answers


You need to add a pragma <path: '/'>

because you have multiple methods with <get>

pragma and no arguments.



+2


source


It seems that adding another pragma to the list method solved the problem.



list
   <get>
   <path: '/'>

   ^ String streamContents: [ :stream |
        self teamMembers do: [ :each |
           stream nextPutAll: each ; crlf ] ]

      

+2


source







All Articles