how to check for the statusCode

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

how to check for the statusCode

Pharo Smalltalk Users mailing list
Hello,

Sorry for asking so much questions but I lost the big picture right now.

Im trying to get the response object back from a api call.

That I can do with :

` response := ZnEasy get: url. `

and I see that it has the fields statusline which has the field code

I thought I could use it like this :  response at: #statusline `
but that give me a error message that  indexes needs to be integers.

How do I get the code field again ?

Roelof
Reply | Threaded
Open this post in threaded view
|

Re: how to check for the statusCode

Sven Van Caekenberghe-2
You *really* should read the HTTP chapters of http://books.pharo.org/enterprise-pharo/

in particular https://ci.inria.fr/pharo-contribution/job/EnterprisePharoBook/lastSuccessfulBuild/artifact/book-result/Zinc-HTTP-Client/Zinc-HTTP-Client.html

not just the Web App chapters.

Also, any general introduction to HTTP (maybe even https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol) will help you.

You can just say

 response statusLine

You also really, really have to learn how to use the tools (the IDE) to help yourself. If you browse the ZnResponse class, you can see all this for yourself. I know there is a steep learning curve, and that it can be intimidating, but the whole idea behind Pharo is that you have this living object system that you can explore and learn from.

The introduction texts (Pharo By Example, the MOOC, etc) all try to learn you that.

Use spotter to find things, use browsers to look at code, use inspectors to look at objects, use senders and implementers, use class references, read class and method comments, study unit tests. Learn from the system.

BTW, ZnEasy is just a simple class side facade, ZnClient is the real thing.

> On 28 Sep 2020, at 20:34, Roelof Wobben via Pharo-users <[hidden email]> wrote:
>
> Hello,
>
> Sorry for asking so much questions but I lost the big picture right now.
>
> Im trying to get the response object back from a api call.
>
> That I can do with :
>
> ` response := ZnEasy get: url. `
>
> and I see that it has the fields statusline which has the field code
>
> I thought I could use it like this :  response at: #statusline `
> but that give me a error message that  indexes needs to be integers.
>
> How do I get the code field again ?
>
> Roelof
Reply | Threaded
Open this post in threaded view
|

Re: how to check for the statusCode

Pharo Smalltalk Users mailing list
Op 28-9-2020 om 21:11 schreef Sven Van Caekenberghe:
You *really* should read the HTTP chapters of http://books.pharo.org/enterprise-pharo/

in particular https://ci.inria.fr/pharo-contribution/job/EnterprisePharoBook/lastSuccessfulBuild/artifact/book-result/Zinc-HTTP-Client/Zinc-HTTP-Client.html

not just the Web App chapters.

Also, any general introduction to HTTP (maybe even https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol) will help you.

You can just say

 response statusLine

You also really, really have to learn how to use the tools (the IDE) to help yourself. If you browse the ZnResponse class, you can see all this for yourself. I know there is a steep learning curve, and that it can be intimidating, but the whole idea behind Pharo is that you have this living object system that you can explore and learn from.

The introduction texts (Pharo By Example, the MOOC, etc) all try to learn you that.

Use spotter to find things, use browsers to look at code, use inspectors to look at objects, use senders and implementers, use class references, read class and method comments, study unit tests. Learn from the system.

BTW, ZnEasy is just a simple class side facade, ZnClient is the real thing.


Thanks,

I think this could help me :

ZnClient new
   enforceHttpSuccess: true;
   ifFail: [ :ex | self inform: 'Cannot get numbers: ', ex printString ];
   get: 'http://zn.stfx.eu/zn/numbers.txt'.

I will try it tomorrow after some sleep 


Roelof