I am new to Pharo/Seaside and it has been a long time since I have used
Smalltalk. I am trying to make a RESTful service and can’t get the pragmas
to work the way I think it should. (This might be the problem already).



 Ie Here is my list method within class TeamMembers which is a direct
subclass of WARestfulHandler.

    list

       <get>

      ^ String streamContents: [ :stream |

       self teamMembers do: [ :each |

           stream nextPutAll: each ; crlf ]

       ]



and



listJson

                <get>

                <produces: 'text/json'>



   ^ (Array streamContents: [ :stream |

      self teamMembers do: [ :each |

         stream nextPut: (Dictionary new

            at: 'name' put: each ;

            yourself) ] ])

      asJavascript







After doing all the proper registration WAAdmin register: TeamMembers at:
'team-members' when I execute in the browser (
http://localhost:8080/team-members) I received the message

/team-members not found
but if I execute (http://localhost:8080/team-members/list), it brings back
the team member list. (However, I didn’t think I would have to add /list to
the URL).



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





However, If I override the TeamMembers>>

createRoutes

                | route pType|

                pType := WAFullMimeTypeMatch main:'text' sub: 'json' .

                route := WASimpleRoute method: 'GET' selector: #listJson
produces: pType consumes: WAWildcardMimeTypeMatch new.

                ^ OrderedCollection new

                                "GET"

                                add: route;

                                add: (WARoute get: #list);

                                yourself.



Then I get the expected behaviour when I browse to (
http://localhost:8080/team-members) and using curl. (ie.

curl -H "Accept: text/json" http://localhost:8080/team-members

to get the Json response.



When I debug the difference in the routes, it looks like using the pragmas,
I get WAComplexRoute(s) but of course in the overridden method
createRoutes, I get WASimpleRoutes.



Is this the way it is supposed to work?




Thanks in advance for any hints.

Reply via email to