A simple blog implementation on NanoBus.
Before you begin, make sure you have the following installed:
-
Clone the nanobus/examples directory -
git clone https://github.com/nanobus/examples.git
-
cd examples/blog
-
Run
docker compose up -d
.
The nanobus invoke <bus file> <operation>
allows you to run nanobus actions in your terminal without having nanobus running
Below is us echoing in a json with the necessary parameters to make a blog post.
echo '{ "userId": "myuserid", "title": "My Blog Title", "body": "This is my blog post" }' | nanobus invoke bus.yaml blogs.v1.Blogs::postBlog
Here are some other method commands you can run (Pass in the id you get from the postblog
response) -
Delete Blog Post:
echo '{ "id": "", "userId": "myuserid" }' | nanobus invoke bus.yaml blogs.v1.Blogs::deleteBlog
Note:
userId
has to be passed because this example does not use authentication/authorization.
Get Single Blog Post:
echo '{ "id": "" }' | nanobus invoke bus.yaml blogs.v1.Blogs::getBlog
Show Feed:
echo '{}' | nanobus invoke bus.yaml blogs.v1.Blogs::getFeed
-
To run the application have it running on localhost:8080, you can run the following command.
-
nanobus
-
Now you have a web service and can make rest calls. Below is an example of a curl command you can run to test out the API calls.
curl -X 'POST' \
'http://localhost:8080/v1/blogs' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"body": "string",
"title": "string",
"userId": "string"
}'
For more info, visit here.