Hey folks, I’m working on a Go backend for my web app and need some guidance on setting up an API for my jQuery AJAX frontend. I’m currently using functions that take input, process data, and return results, but I’m not sure where to head next.
I was considering using a port to listen for JSON function calls and then sending back JSON responses. Does that sound like a good approach? If yes, what would be the best way to implement it?
Also, I’m confused about handling user authentication with Go and AJAX. Should I generate a unique hash for each user, store it as a cookie, keep it in memory, and include it with every API call? Or is there a more effective method or a ready-made solution in Go?
I appreciate any advice since I’m still learning about backend development!
For your Go backend API, I’d recommend using a framework like Gin or Echo as they provide robust routing and middleware support. These frameworks simplify the process of handling JSON requests and responses, which aligns well with your jQuery AJAX frontend.
Regarding authentication, JSON Web Tokens (JWTs) are a popular and secure choice. They’re stateless, which means you don’t need to store session information on the server. You can generate a JWT upon successful login, send it to the client, and have the client include it in the Authorization header for subsequent requests.
For implementation, you could use a library like golang-jwt to handle JWT creation and validation. This approach is more scalable and secure than storing hashes in cookies or memory.
Remember to implement proper error handling and logging in your API for easier debugging and maintenance.
hey, have you tried gin or echo? might make life eaiser for your api. jwt tokens r a cute solution for auth. what challenges r u facing? curious to kno more bout ur project. cheers!
yo alex, gin’s pretty solid for go apis. jwt tokens r great for auth - easy to implement n secure. for ur frontend, axios might b smoother than jquery ajax. wht kinda app u building? sounds interesting! lmk if u need more help