今日已更新 339 条资讯 | 累计 19899 条内容
关于我们

How I Built and Published a .NET NuGet Package for the Giant SMS API

Benjamin Aduo 2026年06月06日 05:27 6 次阅读 来源:Dev.to

A while back, I needed to integrate SMS into a .NET project. Giant SMS had a REST API, but no official .NET client. The only existing library was a PHP one from 6–7 years ago, and it only covered two methods: send and getBalance. So I built my own. It now has nearly 2,000 downloads on NuGet. Here's exactly how I did it. The Problem Wiring up raw HTTP calls to the Giant SMS API in every project gets repetitive fast: Manually setting Authorization headers Remembering which endpoints use token auth vs. username/password Deserializing responses every time Scattering credentials across your codebase I wanted something that felt native to .NET. Configure once in appsettings.json , register with DI, and just call a method. Designing the Public API The first decision was the interface. I wanted consumers to never touch HttpClient directly, and I wanted methods that mapped clearly to what the API actually does: public interface IGiantSmsService { bool IsReady { get ; } Task < SingleSmsResponse > SendSingleMessage ( string to , string msg ); Task < SingleSmsResponse > SendMessageWithToken ( SingleMessageRequest messageRequest ); Task < BaseResponse > SendBulkMessages ( BulkMessageRequest messageRequest ); Task < SingleSmsResponse > CheckMessageStatus ( string messageId ); Task < BaseResponse > GetBalance (); Task < SenderIdResponse > GetSenderIds (); Task < BaseResponse > RegisterSenderId ( RegisterSenderIdRequest senderIdRequest ); } Seven methods, the full surface of the API, no more, no less. The IsReady property is a small but useful addition. It lets consumers do a quick sanity check at startup rather than discovering a missing token on the first SMS send: csharp _isReady = !string.IsNullOrWhiteSpace(_connection.Token) && !string.IsNullOrWhiteSpace(_connection.Username); Handling Two Auth Methods This was the most interesting design challenge. The Giant SMS API uses two different authentication schemes depending on the endpoint: Token-based (Basic Authorization header) —

本文内容来源于互联网,版权归原作者所有
查看原文