How to edit an element with Teapot
Hi This is probably a stupid question but I dare to ask it. I have a tiny teapot application (based on the library example) and I would like to let the use add an item or edit an item. I do want to force the user to do it via the request path with a post or that way ZnClient new url: 'http://localhost:8080/books/1'; formAt: 'author' put: 'SquareBracketAssociates'; formAt: 'title' put: 'Pharo For The Enterprise'; put I know how to do it in Seaside but I feel spoiled because I do not know how to do it in plain html to serve it with Teapot. I noticed that in none of our chapters (Teapot, ZnApplication chapter, tinyblog-teapot, tinyblog-seaside) shows how to do it. -- Using Opera's mail client: http://www.opera.com/mail/
Chapter 11 : Scripting a REST Web Service with Zinc of the Enterprise book
On 17 Dec 2016, at 11:31, stepharong <stepharong@free.fr> wrote:
Hi
This is probably a stupid question but I dare to ask it.
I have a tiny teapot application (based on the library example) and I would like to let the use add an item or edit an item. I do want to force the user to do it via the request path with a post or that way
ZnClient new url: 'http://localhost:8080/books/1'; formAt: 'author' put: 'SquareBracketAssociates'; formAt: 'title' put: 'Pharo For The Enterprise'; put
I know how to do it in Seaside but I feel spoiled because I do not know how to do it in plain html to serve it with Teapot.
I noticed that in none of our chapters (Teapot, ZnApplication chapter, tinyblog-teapot, tinyblog-seaside) shows how to do it.
-- Using Opera's mail client: http://www.opera.com/mail/
I meant section 11 of the Zinc HTTP Server chapter https://ci.inria.fr/pharo-contribution/job/EnterprisePharoBook/lastSuccessfu...
On 17 Dec 2016, at 11:56, Sven Van Caekenberghe <sven@stfx.eu> wrote:
Chapter 11 : Scripting a REST Web Service with Zinc
of the Enterprise book
On 17 Dec 2016, at 11:31, stepharong <stepharong@free.fr> wrote:
Hi
This is probably a stupid question but I dare to ask it.
I have a tiny teapot application (based on the library example) and I would like to let the use add an item or edit an item. I do want to force the user to do it via the request path with a post or that way
ZnClient new url: 'http://localhost:8080/books/1'; formAt: 'author' put: 'SquareBracketAssociates'; formAt: 'title' put: 'Pharo For The Enterprise'; put
I know how to do it in Seaside but I feel spoiled because I do not know how to do it in plain html to serve it with Teapot.
I noticed that in none of our chapters (Teapot, ZnApplication chapter, tinyblog-teapot, tinyblog-seaside) shows how to do it.
-- Using Opera's mail client: http://www.opera.com/mail/
Tx for the pointer. I was planning to read the seaside implementation to understand. I read your Simple Web App but it was not there, nor in Teapot, nor in tinyblog (obviously). So I will have a look at the one. I think that al the docs are only showing displaying information while inputting is the other half of the story. On Sat, Dec 17, 2016 at 12:31 PM, Sven Van Caekenberghe <sven@stfx.eu> wrote:
I meant section 11 of the Zinc HTTP Server chapter
https://ci.inria.fr/pharo-contribution/job/EnterprisePharoBook/ lastSuccessfulBuild/artifact/book-result/Zinc-HTTP-Server/ Zinc-HTTP-Server.html
On 17 Dec 2016, at 11:56, Sven Van Caekenberghe <sven@stfx.eu> wrote:
Chapter 11 : Scripting a REST Web Service with Zinc
of the Enterprise book
On 17 Dec 2016, at 11:31, stepharong <stepharong@free.fr> wrote:
Hi
This is probably a stupid question but I dare to ask it.
I have a tiny teapot application (based on the library example) and I would like to let the use add an item or edit an item. I do want to force the user to do it via the request path with a post or that way
ZnClient new url: 'http://localhost:8080/books/1'; formAt: 'author' put: 'SquareBracketAssociates'; formAt: 'title' put: 'Pharo For The Enterprise'; put
I know how to do it in Seaside but I feel spoiled because I do not know how to do it in plain html to serve it with Teapot.
I noticed that in none of our chapters (Teapot, ZnApplication chapter, tinyblog-teapot, tinyblog-seaside) shows how to do it.
-- Using Opera's mail client: http://www.opera.com/mail/
Ok I read it but I do not understand how I should do it ;( With teapot or Zinc I want to be able to serve an html string (containing a form probably with a submit button) that will let the user to pass some data and that the server can access this data and invoke a method. I want to get the same behavior than textInput in seaside My user has only one web browser. May be this is obvious in the chapter but I do not see it. Stef
Do want to build/use a REST API or do you want to build a simple web app ? I thought you wanted to do the first. The second is easy too, ZnDefaultServerDelegate>>#formTest1: #formTest2: #formTest3: are doing that (in a single handler, generating the page, using the submitted info as well.
On 17 Dec 2016, at 15:13, stepharong <stepharong@free.fr> wrote:
Ok I read it but I do not understand how I should do it ;(
With teapot or Zinc I want to be able to serve an html string (containing a form probably with a submit button) that will let the user to pass some data and that the server can access this data and invoke a method.
I want to get the same behavior than textInput in seaside
My user has only one web browser. May be this is obvious in the chapter but I do not see it.
Stef
On Sat, 17 Dec 2016 15:29:24 +0100, Sven Van Caekenberghe <sven@stfx.eu> wrote:
Do want to build/use a REST API or do you want to build a simple web app
I want to have a small web app that is basically using to teapot to listen and serve
I thought you wanted to do the first.
No because teapot is doing and your section 11 is indeed that.
The second is easy too, ZnDefaultServerDelegate>>#formTest1: #formTest2: #formTest3: are doing that (in a single handler, generating the page, using the submitted info as well.
Ok I will have a look Tx sven. Stef
On 17 Dec 2016, at 15:13, stepharong <stepharong@free.fr> wrote:
Ok I read it but I do not understand how I should do it ;(
With teapot or Zinc I want to be able to serve an html string (containing a form probably with a submit button) that will let the user to pass some data and that the server can access this data and invoke a method.
I want to get the same behavior than textInput in seaside
My user has only one web browser. May be this is obvious in the chapter but I do not see it.
Stef
-- Using Opera's mail client: http://www.opera.com/mail/
Hi sven so I studied your code and I got a solution working. Tx for your support. Now I do not know if what I did is correct. registerRoutes teapot GET: '/' -> '<h1>My game collection</h1>'; output: #html; GET: '/games' -> [ :reg | (self htmlListFor: self games)]; output: #html; GET: '/findDetails/<title>' -> [ :req | collector findMatchingTitle: (req at: #title) ]; output: #json; GET: '/find/<title>' -> [ :req | TeaResponse ok body: (self htmlListFor: (collector findMatchingTitle: (req at: #title))) ]; output: #html; GET: '/add' -> [ :req | self edit: req ]; GET: '/create' -> (Send message: #create: to: self) So I used /add to enter the parameter and pass them to the /create page. in the /create I created the new item and I could redirect to game list (I imagine that this is possible). So now I see tht I could merge add and create into a single page (as you did) and edit: request | title page | title := 'Enter a title'. page := ZnHtmlOutputStream streamContents: [ :html | html page: 'Create game named' do: [ html tag: #form attributes: #(#action 'create' 'accept-charset' 'utf-8' #method #GET) do: [ html str: 'Title'; space; tag: #input attributes: {#type. #input. #name. #input. #value. title}; space; tag: #input attributes: #(#type #submit) ] ] ]. ^ ZnResponse new statusLine: ZnStatusLine ok; entity: (ZnEntity html: page); yourself create: aRequest collector addGame: (GameItem new title: (aRequest at: #input)). ^ ZnResponse new statusLine: ZnStatusLine ok; entity: (ZnEntity html: 'Created!'); yourself
participants (3)
-
Stephane Ducasse -
stepharong -
Sven Van Caekenberghe