Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Your first API with GO & Nitric

Posted on Sep 27 Hey Dev.to community! Today we are diving into an exciting project where we'll create a Profile Management Api using Nitric and GO.This API will handle the creation, updating, and deletion of user profiles. We’ll then extend it to manage profile images. Nitric is a tool that helps developers create applications for the cloud (like AWS, Google Cloud, or Microsoft Azure) quickly and with less repetitive code. It acts as a bridge between your code and the cloud services, making it dead simple to build and deploy your application. By using Nitric, you can focus more on building your application, and less on the specifics of the cloud provider and eliminate the Terraform (or other IaC) project required to deploy it.Learn more about it by checking out some of my other blogs, or heading to the docs.We'll start by creating a new project for our API.Create a project, name it and select your preferred starter template.Next, open the project in your editor of choice.Make sure all dependencies are resolved:The scaffolded project should have the following structure:You can test the project to verify everything is working as expected:and in a separate terminal: The first command starts the Nitric Server using nitric start, which provides local interfaces to emulate cloud resources. Then go run functions/hello runs your functions and allows them to connect.If everything is working as expected you can now delete all files in the functions/ folder, we'll create new functions in this guide.Let's start building the profiles API. Create a file named main.go in the functions directory and add the following:Here we're creating:From here, let's add some features to that function that allow us to work with profiles. You could separate some or all of these request handlers into their own functions if you prefer. For simplicity we'll group them together in this guide.Now that you have an API defined with handlers for each of its methods, it's time to test it locally.and in a separate terminal:Once it starts, the application will receive requests via the API port. You can use cURL, Postman or any other HTTP client to test the API.We will keep it running for our tests. If you want to update your functions, just save them, they'll be reloaded automatically.Update all values in brackets [] and change the URL to your deployed URL if you're testing on the cloud.At this point, you can deploy what you've built to any of the supported cloud providers. To do this start by setting up your credentials and any configuration for the cloud you prefer:Next, we'll need to create a stack. A stack represents a deployed instance of an application, which is a collection of resources defined in your project. You might want separate stacks for each environment, such as stacks for dev, test and prod. For now, let's start by creating a dev stack.Note: You are responsible for staying within the limits of the free tier or any costs associated with deployment.We called our stack dev, let's try deploying it with the up commandWhen the deployment is complete, go to the relevant cloud console and you'll be able to see and interact with your API.To tear down your application from the cloud, use the down command:If you want to go a bit deeper and create some other resources with Nitric, why not add images to your profiles API.Define a bucket named profilesImg with reading/writing permissionsYou can also directly redirect to the photo URL.Update all values in brackets [] and change the URL to your deployed URL if you're testing on the cloud.In this exploration, we created a Profile Management API using Nitric, handled core profile operations, and extended it for image management. Nitric proves to be a reliable companion in swiftly moving from idea to a live, cloud-hosted API. Now it's your turn to expand this project or embark on new adventures with Nitric. Happy coding!This post originally featured on the Nitric website.Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well Confirm For further actions, you may consider blocking this person and/or reporting abuse ByteHide - Sep 18 Nilanchal - Sep 18 Brandon Damue - Aug 30 Jack - Sep 10 Once suspended, rsiv will not be able to comment or publish posts until their suspension is removed. Once unsuspended, rsiv will be able to comment and publish posts again. Once unpublished, all posts by rsiv will become hidden and only accessible to themselves. If rsiv is not suspended, they can still re-publish their posts from their dashboard. Note: Once unpublished, this post will become invisible to the public and only accessible to Rak . They can still re-publish the post if they are not suspended. Thanks for keeping DEV Community safe. Here is what you can do to flag rsiv: rsiv consistently posts content that violates DEV Community's code of conduct because it is harassing, offensive or spammy. Unflagging rsiv will restore default visibility to their posts. DEV Community — A constructive and inclusive social network for software developers. With you every step of your journey. Built on Forem — the open source software that powers DEV and other inclusive communities.Made with love and Ruby on Rails. DEV Community © 2016 - 2023. We're a place where coders share, stay up-to-date and grow their careers.



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

Your first API with GO & Nitric

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×