Authentication

Welcome to the Happyoffer API routes documentation! In this guide, you'll find comprehensive information on the various endpoints available in our API, what they do, and how to use them. Whether you're looking to fetch data, send data, or perform specific actions, this documentation will provide you with the necessary steps.

Basic authentication

For the API part of Happyoffer we will be using Laravel Sanctum. Laravel Sanctum is a lightweight authentication system for Laravel's API, SPA, and mobile applications. It provides a simple way to authenticate users and generate tokens for each user. These tokens can then be used to make authenticated requests to the API.

Sanctum accomplishes this by storing tokens in a database table and authenticating incoming requests via Laravel's built-in cookie-based session authentication services or a token in the Authorization header. This way, it provides a secure, flexible method to authenticate API requests, whether they're from your SPA or mobile application.

When using Sanctum, each user of your application will have multiple API tokens, allowing them to make authenticated requests to the application's endpoints. You can revoke these tokens when users log out of the application to ensure the security of your application.

Postman

This documentation and the provided examples are created using Postman. Postman is a popular API client that makes it easy for developers to create, share, test and document APIs. This makes it easy to explore our API, understand the request and response formats, and interactively test endpoints before writing any code. Please note that while reading this documentation, you may want to have Postman open to follow along with the examples.

API headers

When making requests to different endpoints of the Happyoffer API, it's important to include the correct headers.

For the /api/login request, you must include the "Accept": "application/json" header. This header indicates that the client wants a JSON response.

For all other routes, you need to include the "Authorization": "Bearer YOUR_API_TOKEN" header. This header is used to authenticate your requests, where YOUR_API_TOKEN should be replaced with the actual API token of the user that you retrieve from the /api/login endpoint.

{
  "Accept": "application/json",
  "Authorization": "Bearer YOUR_API_TOKEN"
}

API Base URL

The Happyoffer API uses a base URL with the prefix api for all endpoints. This base URL is essential for making requests to the various API routes provided by Happyoffer. The base URL for the API is:

https://my-online-offer.com/api

When making API requests, you will append the specific endpoint to this base URL to interact with the Happyoffer API. For example, to access the login endpoint, you would use:

https://my-online-offer.com/api/login

Including the api prefix in the URL ensures that your requests are directed to the correct part of the Happyoffer application designated for API interactions.

Was this page helpful?