/LocalBusinesses.Solution

A C# Application that creates an API to store local businesses' information

Primary LanguageC#

Local Businesses API V1.0

A C#/.NET program that creates an API to access a database of local businesses.

By Woo Jin Kim

Technologies Used

  • C#
  • .NET 5.0.102
  • ASP.NET Core MVC 4.8
  • Entity Framework Core
  • MySql
  • Git
  • Identity
  • Postman
  • Swashbuckle

Description

Creates an API on a local machine that access a database containing information on local businesses. API includes:

  • Full CRUD functionality, successfully returning responses to API calls
  • Versioning
  • Pagination
  • Swagger

Setup/Installation Requirements

Note: Make sure you have .NET 5.0 installed. If not, please visit this link

  • Clone this repository to your computer from this repository
  • In your terminal of choice, navigate to the LocalBusinesses directory
  • Create a file named "appsettings.json" in this directory
  • Add the following lines of code to your newly created "appsettings.json" file and save.
{
    "Logging": {
    "LogLevel": {
      "Default": "Warning",
      "Microsoft": "Information",
      "System": "Information"
    }
  },
  "AllowedHosts": "*";
  "ConnectionStrings": {
  "DefaultConnection": "Server=localhost;Port=3306;database=local_businesses;uid=root;pwd=[YOUR PASSWORD];"
  }
}
NOTES:
- [YOUR PASSWORD] MUST be the same password as that on your local machine/server.
- Port, database, and uid values may vary depending on configuration.

For further help on database configuration, please see here

  • Back in the terminal, enter dotnet build and ensure that there are no errors
  • Enter dotnet ef database update into the terminal to build the database
  • Enter dotnet run into the terminal to run the application

API Documentation

Click here to see full API Documentation

Note: This application features Swagger. To view the documentation on SwaggerUI, please ensure the application is running (run the command dotnet run in the terminal) and open this link in your browser.

Version: 1.0

  • Base URL

http://localhost/5000 
or 
https://localhost/5001

  • HTTP Requests:

GET /api/businesses
POST /api/businesses
GET /api/businesses/{id}
PUT /api/businesses/{id}
DELETE /api/businesses/{id}

  • URL Parameters

Parameter Type Default Required Description
name string none false Return businesses that match queried name.
category string none false Return businesses that match the queried category.
hoursopen string none false Return businesses that have an Open time earlier than queried.
hoursclose string none false Return businesses that have a closing time later than queried.
page string none false Determines which page businesses is displayed. See Pagination section for more details
pageSize string none false Determines how many businesses are displayed per page. See Pagination section for more details

Example Query

https://localhost:5000/api/Businesses/?name=Mama's&hoursopen=0800

  • Sample Response

  {
    "businessId": 5,
    "name": "Mama's",
    "category": "Restaurant",
    "ownedBy": "Cooking Mama",
    "address": "5 Mom St.",
    "phoneNumber": "180000085",
    "hoursOpen": "05:00",
    "hoursClose": "23:00"
  }

  • Pagination

If you would like to view the database in pages, add the page parameter to your query. By default, each page will display up to 20 businesses. To modify the number of businesses shown per page, please add the pageSize parameter

Example Query

https://localhost:5000/api/businesses/?page=1&pageSize=42

Known Bugs

  • None at the moment.

License

MIT

Contact Information

Woo Jin Kim (kimwoojin211@gmail.com)


Copyright (c) 2021 Woo Jin Kim