DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Leveling Up My GraphQL Skills: Real-Time Subscriptions
  • How Do the Docker Client and Docker Servers Work?
  • Apache Ranger and AWS EMR Automated Installation and Integration Series (5): Windows AD + Open-Source Ranger
  • Apache Ranger and AWS EMR Automated Installation and Integration Series (4): OpenLDAP + Open-Source Ranger

Trending

  • Advancing Your Software Engineering Career in 2025
  • Navigating and Modernizing Legacy Codebases: A Developer's Guide to AI-Assisted Code Understanding
  • Navigating Change Management: A Guide for Engineers
  • Dropwizard vs. Micronaut: Unpacking the Best Framework for Microservices
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. CLI for REST APIs

CLI for REST APIs

In this article, take a look at CLI for REST APIs.

By 
Ivan Nikitsenka user avatar
Ivan Nikitsenka
·
Apr. 13, 20 · Opinion
Likes (2)
Comment
Save
Tweet
Share
20.9K Views

Join the DZone community and get the full member experience.

Join For Free

CLI for REST API

Command line interface for backend services is not always considered a required item in the production readiness checklist. Why do we need to spend additional time if we already have swagger documentation, postman collection, end-to-end tests, and a UI application? REST APIs are built for developers, and technical documentation should give all the required information to understand how it works. 

Yes, but a CLI application can provide the user with the experience to answer most of the questions very quickly. Together, with good documentation, it brings the fastest way of integration between two parties. Also, CLI applications can significantly simplify REST API interactions by hiding complexity and encapsulating authentication mechanisms. Lets, for example, create a simple CLI application for google APIs to get user emails.

Welcome Page

This is the welcome page of a GLI application. The example is of the command line interface for Google API services.

 

The same as a web home page the cli command can also have a welcome page shown using basic command execution. You can find some contact information and a pretty ANSI logo here.  

Authentication

CLI applications can simplify the authentication process. Authentication in third party services using a browser is a workable flow for CLI as well. Just run the login command, provide all required permissions for the app, and you can start playing with REST. For example, this is how Google auth works together with our CLI example:

Specify a callback URL to your localhost server, start local HTTP server to listen to only this URL, and close it immediately once you get your request back. Start/stop HTTP server for this purpose using golang can be done very easily and fast. For more details, please take a look at the example source code.   

Quick User Experience and Self Discovery

According to the Standards for Command Line Interfaces, every application should support two options:
--version and --help. This makes CLI applications self-discoverable and fully documented right in place without the need to open a browser. While switching tabs between CLI and the browser is an extremely fast operation, switching your mind to browser and back could be very disruptive. This also can work as documentation for the REST API itself with working examples right into place.

Using the --help command, we can see examples of commands and try them immediately to see the actual response. Applying it to all subcommands provides all required information to work with the application. 

 

Automation

The great power of CLI is automation. Daily routine tasks such as reporting time in time tracker systems or sending status report emails to your manager can be replaced with CLI commands easily. Going further, mapping the CLI language to human language is simpler than GUI and also much more easily adoptable for users with disabilities.

High level end-to-end or smoke tests can be written using a number of sequential CLI commands executed one by one. Zero and non-zero return codes can be used to verify the results and stop CI/CD pipeline from further execution.   

Summary

In the early PC's days, command line applications were popular because of the lack of compute resources. This is not a case in our days. Working time of software engineers is the most valuable resource and costs burden for businesses. Imagine how many resources you can save by simplifying integrations between squads, eliminating GUI web applications for internal B2B processes and automating daily activities. With testing automation capabilities and resource savings, the pros can be tremendous.  

Github link to the example: https://github.com/nikitsenka/gli

Command-line interface REST Web Protocols

Opinions expressed by DZone contributors are their own.

Related

  • Leveling Up My GraphQL Skills: Real-Time Subscriptions
  • How Do the Docker Client and Docker Servers Work?
  • Apache Ranger and AWS EMR Automated Installation and Integration Series (5): Windows AD + Open-Source Ranger
  • Apache Ranger and AWS EMR Automated Installation and Integration Series (4): OpenLDAP + Open-Source Ranger

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!