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 comma…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Јане Џумеркоски

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


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Јане Џумеркоски


Print Share Comment Cite Upload Translate Updates
APA

Јане Џумеркоски | Sciencx (2022-10-20T13:16:55+00:00) Testing The Endpoints 🧪. Retrieved from https://www.scien.cx/2022/10/20/testing-the-endpoints-%f0%9f%a7%aa/

MLA
" » Testing The Endpoints 🧪." Јане Џумеркоски | Sciencx - Thursday October 20, 2022, https://www.scien.cx/2022/10/20/testing-the-endpoints-%f0%9f%a7%aa/
HARVARD
Јане Џумеркоски | Sciencx Thursday October 20, 2022 » Testing The Endpoints 🧪., viewed ,<https://www.scien.cx/2022/10/20/testing-the-endpoints-%f0%9f%a7%aa/>
VANCOUVER
Јане Џумеркоски | Sciencx - » Testing The Endpoints 🧪. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/10/20/testing-the-endpoints-%f0%9f%a7%aa/
CHICAGO
" » Testing The Endpoints 🧪." Јане Џумеркоски | Sciencx - Accessed . https://www.scien.cx/2022/10/20/testing-the-endpoints-%f0%9f%a7%aa/
IEEE
" » Testing The Endpoints 🧪." Јане Џумеркоски | Sciencx [Online]. Available: https://www.scien.cx/2022/10/20/testing-the-endpoints-%f0%9f%a7%aa/. [Accessed: ]
rf:citation
» Testing The Endpoints 🧪 | Јане Џумеркоски | Sciencx | https://www.scien.cx/2022/10/20/testing-the-endpoints-%f0%9f%a7%aa/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.