The Seaside book REST chapter should be deprecated or changed. Take a look here for the updated info: https://github.com/SeasideSt/Seaside/wiki/Seaside-REST <https://github.com/SeasideSt/Seaside/wiki/Seaside-REST> Johan
On 30 Jul 2017, at 01:46, Greg Hutchinson <the.greg.hutchinson@gmail.com> wrote:
That worked - thanks very much.
On 29 July 2017 at 16:13, Esteban A. Maringolo <emaringolo@gmail.com <mailto:emaringolo@gmail.com>> wrote: Did you try setting the pragma <path: '/'> in the list method? Esteban A. Maringolo
2017-07-28 18:40 GMT-03:00 Greg Hutchinson <the.greg.hutchinson@gmail.com <mailto:the.greg.hutchinson@gmail.com>>:
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 <http://localhost:8080/team-members>) I received the message
/team-members not found but if I execute (http://localhost:8080/team-members/list <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 <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 <http://localhost:8080/team-members>) and using curl. (ie.
curl -H "Accept: text/json" http://localhost:8080/team-members <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.
--