HTTPS POST and PlantUML, your best friend.
Hello!!!
This will be a short post
Currently I am working on automating the creation of PlantUML diagrams and embed them into Word documents and Excel Spreadsheets (Yes that is a thing)
But instead of copying the image from the PlantUML server, I will be generating the diagram dynamically and obtain the image as a stream and save into the document or anything really.
Enter the POST verb for the PlantUML server.
If you remember, we created a server from this post
https://darthseldon.net/plantuml-and-nginx-your-own-uml-designer/
We will be using the same server for our purposes.
I will be using Postman, but you can use CURL or any http client you want to use.
Add a post request to your server
As an example, I will use http://localhost:8080/png
You will notice the png at the end, this is the endpoint that will return the response from the server in that format.
Now for the content of the request, we will be using the sample for a sequence diagram
@startuml
'standard libraries
!include <C4/C4_Container>
!include <azure/AzureCommon>
!include <azure/Databases/AzureSqlServer>
!include <tupadr3/common>
!include <office/Servers/application_server>
!include <office/Concepts/application_generic>
'header
title Stylish Sequence Diagram
'actors and participants
actor "Client" as client
participant "<$application_server>\nIdentity Server Provider" as idp
participant "<$application_generic>\nAPI" as api
participant "<$AzureSqlServer>\nProducts Database" as database
'interactions
autonumber "<b>[000]"
group Authentication
client -> idp: Authentication Request
activate idp
idp --> client: Authentication Response
deactivate idp
end
group Obtain Products
client -> api: Get Products
activate api
api -> database : Query Products
activate database
database --> api : Products
deactivate database
api --> client : JSON Products
deactivate api
end
'footer
footer v1.0
@enduml

And TA-DA

The result is an image/png

You can stream it, save it, resend it, etc. The possibilities are quite a few
How about other formats? Well, if you change the png for svg, it will create it as vector graphics


Other formats are:
- png
- svg
- txt (ascii)

Pretty cool. Like I said short post.
Happy coding!!!