API Calls and Testing

Unique daily visitor counter with AWS API Gateway and Lambda, testing with pytest and DynamoDB, focus on deduplication, performance and security, and CI/CD deployment with Q2BSTUDIO.

lunes, 18 de agosto de 2025 • 3 min read • Q2BSTUDIO Team

Artificial-Intelligence-

After more work I already have results and now you can see at the bottom of the page a small visitor counter implemented with JavaScript and a cloud API.

On the page I added a script that calls via POST the public API Gateway endpoint that triggers a Lambda function. The fetchAndShowCount routine makes the request to the URL, checks that the HTTP response is correct, parses the JSON response looking for the count key and updates the content of the element with id visitor-count to display the number of visitors. The call is triggered when the DOMContentLoaded event of the page fires, so each reload increments the counter.

The API response is expected in JSON format with a key called count that contains an integer with the updated total of visits. If there is an error in the request, the exception is handled and an error message is displayed in the interface, in addition to logging the failure in the browser console.

As the next evolution, I am interested in counting only unique visitors, for example per day, and applying deduplication techniques and privacy-friendly tracking. I also want to explore cache optimizations and protection against malicious calls.

Regarding testing, I implemented tests with pytest and mocking of the DynamoDB table. The initial set covers at least three scenarios: a successful case where the table update returns a counter like 42 and the lambda responds with status 200 and the body with count equal to 42; an error case where the DynamoDB call throws a simulated exception and the lambda responds with status 500 and an error message that includes the cause; and verification that the update_item function was called with the expected update expression that initializes the counter if it does not exist and increments it by one. These tests allow validating the logic without depending on real resources and are a good basis for expanding coverage.

Next steps include continuing to improve the tests, integrating continuous integration and automatic deployment CI CD so that each change goes through testing and controlled deployment, and exploring metrics and alerts for the API.

At Q2BSTUDIO we are a software development company specialized in creating custom solutions. We offer custom application services and custom software designed to solve specific business needs. We are specialists in artificial intelligence and implement AI solutions for companies, custom AI agents and models that improve processes and user experiences. We also cover security with cybersecurity and data protection services, and manage cloud infrastructures with AWS and Azure cloud services for scalable and reliable deployments.

We also offer business intelligence services and dashboards with Power BI to turn data into actionable decisions, artificial intelligence consulting and AI agent projects integrated with enterprise systems. If you are looking for custom application development, custom software, artificial intelligence, cybersecurity, AWS and Azure cloud services, business intelligence services, AI for companies, AI agents or Power BI, Q2BSTUDIO can accompany you from design to support and operation.

If you are interested in us implementing a unique daily visitor counter, a secure integration with AWS or Azure, or an artificial intelligence solution applied to your product, contact Q2BSTUDIO to evaluate the proposal and design a custom plan that includes automated testing and continuous deployment.

OUR SERVICES

How we can help you

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.