Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tutorial? #85

Closed
darth-cheney opened this issue Dec 17, 2019 · 4 comments
Closed

Tutorial? #85

darth-cheney opened this issue Dec 17, 2019 · 4 comments

Comments

@darth-cheney
Copy link

The docs section has a pretty good charting of the architecture of this library, but is there something like a tutorial available? After installing and reading around -- including looking through the tests -- I'm not even sure how to get the pet example running in a live image. Any pointers appreciated!

@gcotelli
Copy link
Member

gcotelli commented Dec 18, 2019

Here are the scripts I've used during my ESUG presentation (the first one startups the API, and the others use ZnClient for resource creation or update), you can use the web browser for the endpoints implementing GET:

I haven't tested it against the latest version but if something is missing is probably something in the configuration.

| api |
api := HTTPBasedRESTfulAPI
configuredBy: {
    #port -> 9999.
    #serverUrl -> ('http://localhost' asUrl port: 9999)
    }
installing: {
    SouthAmericanCurrenciesRESTfulController new.
    PetsRESTfulController new.
    PetOrdersRESTfulController new
    }.

api
    install;
    start

-------------

"Create PET"

|  baseUrl mediaType |

baseUrl := 'http://localhost:9999' asUrl.
mediaType := 'application/vnd.stargate.pet+json;version=1.0.0' asZnMimeType.
ZnClient new
    beOneShot;
    url: baseUrl / 'pets' asUrl;
    entity: ( ZnEntity with: '{"name":"Firulais","type":"dog"}' ofType: mediaType);
    setAccept: mediaType;
    post;
    response.
    
ZnClient new
    beOneShot;
    url: baseUrl / 'pets' asUrl;
    entity: ( ZnEntity with: '{"name":"Pipo","type":"dog"}' ofType: mediaType);
    setAccept: mediaType;
    post;
    response

-------------

"Create Order"

|  baseUrl mediaType |

baseUrl := 'http://localhost:9999' asUrl.
mediaType := 'application/vnd.stargate.order+json;version=1.0.0' asZnMimeType.
ZnClient new
    beOneShot;
    url: baseUrl / 'orders' asUrl;
    entity: ( ZnEntity with: '{"date":"2018-10-24T18:05:46.418Z","pet":"http://localhost:9999/pets/2"}' ofType: mediaType);
    setAccept: mediaType;
    post;
    response.

----------------


"Complete Order"

|  baseUrl mediaType |

baseUrl := 'http://localhost:9999' asUrl.
mediaType := 'application/vnd.stargate.order+json;version=1.0.0' asZnMimeType .
ZnClient new
    beOneShot; 
    url:  'http://localhost:9999/orders/1/complete' asUrl;
    setAccept: mediaType;
    post;
    response.

-----------------

"Create Comment"

|    mediaType |
 
mediaType := ZnMimeType textPlain.
ZnClient new
    beOneShot;
    url:  'http://localhost:9999/orders/1/comments' asUrl;
    entity: ( ZnEntity text: 'Hello ESUG!');
    post;
    response.

----------


"Cancel the order"

|    mediaType |
 
mediaType := ZnMimeType textPlain.
ZnClient new
    beOneShot;
    url:  'http://localhost:9999/orders/1/cancel' asUrl;
    post;
    response.

@darth-cheney
Copy link
Author

Thank you, this is useful. I am not able to run the first part (initialization of the api) due to a KeyNotFound exception: #operations not found in Dictionary. I've tried to debug but I'm still not sure what is "supposed" to be happening

@gcotelli
Copy link
Member

Something like

| api |
api := HTTPBasedRESTfulAPI
configuredBy: {
    #port -> 9999.
    #serverUrl -> ('http://localhost' asUrl port: 9999).
    #operations -> 
      (Dictionary new 
	at: #authSchema put: 'basic';
	at: #authUsername put: 'test';
	at: #authPassword put: 'test';
	yourself )
    }
installing: {
    SouthAmericanCurrenciesRESTfulController new.
    PetsRESTfulController new.
    PetOrdersRESTfulController new
    }.

api
    install;
    start

can get you started for testing.

I suggest using JWT as the authentication scheme for more serious reasons (just take a look at the Operations documentation)

@darth-cheney
Copy link
Author

Awesome thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants