-
Notifications
You must be signed in to change notification settings - Fork 3
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
Comments
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. |
Thank you, this is useful. I am not able to run the first part (initialization of the api) due to a KeyNotFound exception: |
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) |
Awesome thanks |
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!
The text was updated successfully, but these errors were encountered: