Skip to content

CMP315/API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API

The back-end of the Password Manager.

Run Locally

  1. Install Python
  2. Install Git
  3. Clone the project
  git clone https://github.com/CMP315/API.git CMP315-API
  1. Go to the project directory
  cd CMP315-API
  1. Create .env File
  2. Install dependencies
  pip install -r requirements.txt
  1. Start the server
  python src/main.py

API Documentation

View Here @ Postman.co

Environment Variables

To run this project, you will need to add the following environment variables to your .env file

NAME TYPE DEFAULT VALUES
MONGODB_CONNECTION_URL String mongodb+srv://USERNAME:[email protected]/?retryWrites=true&w=majority&appName=Cluster0
DEBUG Boolean true
HTTPS Boolean false
DATABASE_NAME String cmp315-api

Example .env File

If you are following the installation steps above, you should put the .env file within the CMP315-API folder.

DEBUG=true
HTTPS=false
MONGODB_CONNECTION_URL=mongodb+srv://cmp315:[email protected]/?retryWrites=true&w=majority&appName=Cluster0
DATABASE_NAME=cmp315-api

Usage/Examples

using System;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main(string[] args)
    {
        // Create an instance of HttpClient
        using (HttpClient client = new HttpClient())
        {
            try
            {
                // Call the API endpoint
                HttpResponseMessage response = await client.GetAsync("https://api.example.com/data");
                
                // Check if the response is successful
                if (response.IsSuccessStatusCode)
                {
                    // Read the response content as a string
                    string content = await response.Content.ReadAsStringAsync();
                    
                    // Output the response content
                    Console.WriteLine(content);
                }
                else
                {
                    Console.WriteLine($"Failed to call the API. Status code: {response.StatusCode}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"An error occurred: {ex.Message}");
            }
        }
    }
}