Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 20, 2022 01:16 pm GMT

Testing The Endpoints

After completing the implementation of the handlers and the endpoints, now it's time to test the all thing.

Start the project with go run main.go (main.go file is the entry point) and open http://localhost:1323/ in browser, or run the following command in your terminal

curl -X GET http://localhost:1323

If you got the following message that means that the server is working as expected.

{  "message":"Welcome to Go URL Shortener with Redis !"}

Now let's create short URL for the provided long URL. For this scenario, use the POST endpoint /encode, with the following body as an example:

{  "long_url": "https://go.dev/doc/tutorial/getting-started",  "user_id": "UwQPr3aIf9dM5x7r"}
curl -X POST http://localhost:1323/encode \ -H 'Content-Type: application/json' \-d '{"long_url": "https://go.dev/doc/tutorial/getting-started", "user_id": "UwQPr3aIf9dM5x7r"}'

You can use any rest client you have installed locally.

The response should look like the json below:

{  "short_url":"http://localhost:1323/dysg5Fas"}

And finally, to get the initial long URL, use the GET endpoint /decode with the shortURL specified as path parameter:

curl -X GET http://localhost:1323/decode/dysg5Fas

As response we should get JSON with the long URL corresponding to the provided short URL:

{  "long_url":"https://go.dev/doc/tutorial/getting-started",  "short_url":"http://localhost:1323/dysg5Fas"}

If everything was right, we can say that our application works flawlessly!

Originally published at projectex.dev


Original Link: https://dev.to/janedzumerko/testing-the-endpoints-2ipg

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To