/Office-Management-APIs

Creating a set of API endpoints to manage office-related data for an organization.

Primary LanguagePython

Office-Management-APIs

Creating a set of API endpoints to manage office-related data for an organization.

Objective:

API is developed using Python (AWS Lambda without any framework) and hosted on AWS Lambda. Using Amazon DynamoDB to access database.

Amazon DynamoDB

Amazon DynamoDB is a fully managed NoSQL database service that provides fast and predictable performance with seamless scalability. We can use Amazon DynamoDB to create a database table that can store and retrieve any amount of data, and serve any level of request traffic. Amazon DynamoDB automatically spreads the data and traffic for the table over a sufficient number of servers to handle the request capacity specified by the customer and the amount of data stored, while maintaining consistent and fast performance.

Step1: Creating DynamoDB Tables

dynamodb1

Table1: office_data id : String (Partition key) name : String location :String Table2: office_transactions officeid : String (Partition key) amount : Number transactionType : String

API Gateway

Amazon API Gateway lets developers connect non-AWS applications to AWS back-end resources. It is a fully managed service that makes it easy for developers to create, publish, maintain, monitor, and secure APIs at any scale. APIs act as the "front door" for applications to access data, business logic, or functionality from your backend services.

RESTful API:

A RESTful API is an architectural style for an application programming interface that uses HTTP requests to access and use data. That data can be used to GET , PUT , POST and DELETE data types, which refers to reading, updating, creating and deleting operations related to resources.

Step2: Creating API Gateway

API1 API2 Resources inside the API:

  • office:
  • offices: -> transaction
  • status:

Deploying API staging it as officedata to invoke the Staging URL: https://qrba02lwn4.execute-api.ap-south-1.amazonaws.com/officedata

AWS Lambda

AWS Lambda is a serverless, event-driven compute service that lets us run code for virtually any type of application or backend service without provisioning or managing servers. It lets us automatically run code in response to many types of events, such as HTTP requests from the Amazon API gateway, table updates in Amazon DynamoDB, and state transitions.

Step3: Creating AWS Lambda Function

Lambda1 Deploying the lamda_function.py on the code Source

Lambda2 Lambda3 Lambda4

API End-Points Using Postman

1. Retrieve All Offices

    Endpoint: /offices
    HTTP Method: POST
    Functionality: Retrieves all office records.

req1

   Edge Cases and Validations:
   * When there is no Office      

req6

2. Create office

  Endpoint: /office
  HTTP Method: POST
  Input:
  {
     "id" : "1",
     "name" : "Head Office",
     "location" : "New York"
  }
  Request Body: Json containing office details.
  Functionality: Creates a new office.

req2

3. Update Office

  Endpoint: /offices
  HTTP Method: PATCH
  Input:
  {
     "id" : "1",
     "updateKey" : "name",
     "updateValue" : "NewofficeName"
  }
  Path Parameter : office
  Request Body : Json containing updated office details.
  Functionality: Updates an existing office.

req3

4. Delete Office

  Endpoint: /offices
  HTTP Method: DELETE
  Functionality: Deletes an existing office.

req4

  Edge Cases and Validations:
  * Validating that the officeId exists before attempting a delete and Handle scenarios where the officeId does not exist.

req7

5. Create Office Transaction

  Endpoint: /offices/transactions
  HTTP Method: POST
  Request Body: Json containing the transaction details.
  Functionality: Creates a new office transaction.

req5

  Edge Cases and Validations:
  * Ensure that the amount is a positive number.

req8

  *Validate that the transactionType is either EXPENSE or INCOME .

req9