Pharo Seaside RESTful services pragma question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Pharo Seaside RESTful services pragma question

Greg Hutchinson

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 | Threaded
Open this post in threaded view
|

Re: Pharo Seaside RESTful services pragma question

Esteban A. Maringolo
Did you try setting the pragma <path: '/'> in the list method?
Esteban A. Maringolo


2017-07-28 18:40 GMT-03:00 Greg Hutchinson <[hidden email]>:

> 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 | Threaded
Open this post in threaded view
|

Re: Pharo Seaside RESTful services pragma question

Greg Hutchinson
That worked - thanks very much.

On 29 July 2017 at 16:13, Esteban A. Maringolo <[hidden email]> 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 <[hidden email]>:
> 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 | Threaded
Open this post in threaded view
|

Re: Pharo Seaside RESTful services pragma question

Johan Brichau-2
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

Johan

On 30 Jul 2017, at 01:46, Greg Hutchinson <[hidden email]> wrote:

That worked - thanks very much.

On 29 July 2017 at 16:13, Esteban A. Maringolo <[hidden email]> 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 <[hidden email]>:
> 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 | Threaded
Open this post in threaded view
|

Re: Pharo Seaside RESTful services pragma question

Stephane Ducasse-3
Argh I will try to migrate it to Pillar for real. 

On Sun, Jul 30, 2017 at 10:21 AM, Johan Brichau <[hidden email]> wrote:
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

Johan


On 30 Jul 2017, at 01:46, Greg Hutchinson <[hidden email]> wrote:

That worked - thanks very much.

On 29 July 2017 at 16:13, Esteban A. Maringolo <[hidden email]> 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 <[hidden email]>:
> 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 | Threaded
Open this post in threaded view
|

Re: Pharo Seaside RESTful services pragma question

Greg Hutchinson
In reply to this post by Johan Brichau-2
Thanks Johan - that link looks very helpful.


On 30 July 2017 at 02:21, Johan Brichau <[hidden email]> wrote:
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

Johan


On 30 Jul 2017, at 01:46, Greg Hutchinson <[hidden email]> wrote:

That worked - thanks very much.

On 29 July 2017 at 16:13, Esteban A. Maringolo <[hidden email]> 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 <[hidden email]>:
> 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.
>




--




--