Skip to content
This repository has been archived by the owner on Mar 11, 2022. It is now read-only.

how to write client code #4

Closed
lanwenchang opened this issue Mar 29, 2020 · 10 comments
Closed

how to write client code #4

lanwenchang opened this issue Mar 29, 2020 · 10 comments
Labels
question Further information is requested

Comments

@lanwenchang
Copy link

I had run server success, and then how to write client code to test the ShopingChartEntity.

I try to send http request, but return 404.

curl http://127.0.0.1:8080/carts/lan -v
@sleipnir
Copy link

sleipnir commented Mar 30, 2020

Hi @lanwenchang

Thanks for playing a little bit with this.

To run the example in a development environment you will need to have the cloudstate proxy running and pointing to where your 'user function' is running as well.

If you have Cloudstate CLI installed you can run this command:

cloudstate run --only-proxy --user-function-port=8080

Otherwise you will need to manually run the proxy on the Docker:

docker run --net=host --name=proxy --env HTTP_PORT: 9000 --env USER_FUNCTION_PORT:8080 cloudstateio/cloudstate-proxy-native-dev-mode:latest

After you have your application and the proxy running, you can make requests to the proxy, one of which could be:

# SET the body of request
export POST = '{"productId": "foo", "name": "A foo", "quantity": 10}'

# Add items to the shopping cart
curl -s -X POST http://localhost:9000/cart/1/items/add -H "Content-Type: application/json" -d "$POST"

# Repeat operation
curl -s -X POST http://localhost:9000/cart/1/items/add -H "Content-Type: application/json" -d "$POST"

# Get the shopping cart
curl http://localhost:9000/carts/1

# Get items from the shopping cart
curl http://localhost:9000/carts/1/items

For more information specific to Cloudstate I suggest you access the official project documentation:

https://cloudstate.io/docs/

Or our channel on the Gitter:
https://gitter.im/CloudState-IO/community

@sleipnir
Copy link

You could test via any grpc client, but via http is easier.
I hope I helped with this information

@sleipnir sleipnir added the question Further information is requested label Mar 30, 2020
@sleipnir
Copy link

ping @lanwenchang

@lanwenchang
Copy link
Author

lanwenchang commented Apr 1, 2020

Hi, @sleipnir

I had try to use proxy on the Docker, but it does not work. Because of the docker host mode can't work in Mac. see docker/for-mac#2716

So I trying to do with cloudstate-cli, unfortunately, there some wrong in my brew, so I had to fix it first. And then I will going to check if curl can work

thanks for your advice :)

@sleipnir
Copy link

sleipnir commented Apr 1, 2020

Hi @lanwenchang
Did you try this WA ?
This issue is interesting because it means that the same error will also occur with the cloudstate cli since it also depends on the host network to share the necessary namespaces.
I think in your case for now it would be necessary to generate a docker image and test everything via docker. Perhaps the functionality of the Cloudstate CLI for Swarm could help you, but I am having trouble generating new versions of the Cloudstate CLI for MacOS that I have not yet been able to resolve.
But in theory you could run your image of the user role created during the build of the example project with the proxy image via Podlike Swarm, or run everything on the Minikube :)

@sleipnir
Copy link

sleipnir commented Apr 3, 2020

Any progress @lanwenchang ?

@lanwenchang
Copy link
Author

not yet

there some wrong with the cloudstate-ci install

➜  ~ brew install cloudstate-cli
Updating Homebrew...
==> Installing cloudstate-cli from sleipnir/cloudstate-cli
==> Downloading https://github.com/sleipnir/cloudstate-cli/releases/download/0.4.1/cloudstate-0.4.1-osx.tar.gz
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws.com/216043821/0d033800-1516-11ea-9a1c-3f8dec95a28b?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20200404%2Fus-east-1%2Fs3%2Faws4_
################                                                          22.6%
curl: (56) LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 60

curl: (22) The requested URL returned error: 403 Forbidden
Error: An exception occurred within a child process:
  DownloadError: Failed to download resource "cloudstate-cli"
Download failed: https://github.com/sleipnir/cloudstate-cli/releases/download/0.4.1/cloudstate-0.4.1-osx.tar.gz

@sleipnir
Copy link

sleipnir commented Apr 4, 2020

Sorry for that but this related of this mungotinae/cloudstate-cli#22

@sleipnir
Copy link

Hi! @lanwenchang Try again:

brew tap sleipnir/cloudstate-cli
brew install sleipnir/cloudstate-cli/cloudstate-cli

Sorry for the delay I was a little busy in the past few weeks. I believe everything is ok now but let me know if there are still any problems or questions.

@sleipnir
Copy link

Closed due to inactivity

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants