chatty API
See original GitHub issueWhy is the python code so much smaller than the Java/C#? We should have similar (small) verbosity on all the platforms. I see no good reason not to create a nice DSL on top of the more verbose builders.
Example: python code to read timeseries:
client = monitoring.Client()
metric = 'compute.googleapis.com/instance/cpu/utilization'
query_results = client.query(metric, minutes=5).iter(headers_only=True)
for result in query_results:
print(result)
vs java code to read timeseries
MetricServiceClient metricServiceClient = MetricServiceClient.create();
String projectId = System.getProperty("projectId");
ProjectName name = ProjectName.create(projectId);
// Restrict time to last 20 minutes
long startMillis = System.currentTimeMillis() - ((60 * 20) * 1000);
TimeInterval interval = TimeInterval.newBuilder()
.setStartTime(Timestamps.fromMillis(startMillis))
.setEndTime(Timestamps.fromMillis(System.currentTimeMillis()))
.build();
ListTimeSeriesRequest.Builder requestBuilder = ListTimeSeriesRequest.newBuilder()
.setNameWithProjectName(name)
.setFilter("metric.type=\"compute.googleapis.com/instance/cpu/utilization\"")
.setInterval(interval)
.setView(ListTimeSeriesRequest.TimeSeriesView.HEADERS);
ListTimeSeriesRequest request = requestBuilder.build();
PagedResponseWrappers.ListTimeSeriesPagedResponse response = metricServiceClient
.listTimeSeries(request);
System.out.println("Got timeseries headers: ");
for (TimeSeries ts : response.iterateAll()) {
System.out.println(ts);
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
#28 - Avoid chattiness in REST APIs
Chatty API is one that requires consumer to make tremendous (subjective matter) amount of distinct API calls to get needed information about ...
Read more >Chatty I/O antipattern - Performance antipatterns for cloud apps
For example, the following web API exposes the individual properties of User objects through individual HTTP GET methods.
Read more >How to balance chunkiness against chattiness when ...
Consumers can balance between chunky responses and chatty API calls all by themselves. One thing worth mentioning is the performance of the Hash ......
Read more >API Reference – chatty v0.5.0 - HexDocs
Chatty. This module defines the public API for interacting with the IRC connection and the hook mechanism. Chatty.Connection · Chatty.Connection.UserInfo.
Read more >A look at chatty vs chunky RESTful web services | On the ROA
Chatty services tend to be ones that return simplified information and use more fine-grained operations. Chunky services tend to return ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That being said : I still think its worth thinking of how we could simplify some of the generic statements here, which might be applicable across multiple libraries.
Constructing a resource
ProjectName
with the projectId : comes up for Pub/Sub as well. It would be good to users to provide projectId if required, and allow for the generated code to autodetect projectId withServiceOptions.getDefaultProjectId()
.A
TimeInterval
helper which can possibly provide a start/end time and duration, so this amount of code does n’t become necessary. Java users are used to simpler ways of building time intervals like here.It looks like this has answered the original question, acknowledging that it is still not as concise the as the Python. Please reopen or create a new issue if there is further iteration required.