GithubHelp home page GithubHelp logo

go-crud-api's Introduction

Go RESTful API with Gorilla Mux

This project demonstrates a simple RESTful API written in Go (Golang) using the Gorilla Mux router for handling HTTP requests.

Features

  • CRUD Operations: Supports Create, Read, Update, and Delete operations for managing educational records.
  • JSON Serialization: Data is exchanged in JSON format between the client and the server.
  • Sample Data: Initial sample data for educational records is provided for testing purposes.
  • Dynamic ID Generation: IDs for new records are dynamically generated using a random number generator.

Prerequisites

  • Go (Golang) installed on your system.
  • github.com/gorilla/mux package for routing.

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/your-repo.git
  2. Navigate to the project directory:

    cd your-repo
  3. Install dependencies:

    go mod tidy

Usage

  1. Start the server:

    go run main.go
  2. The server will start running on port 8081 by default. You can access the API endpoints using tools like cURL or Postman.

API Endpoints

  • GET /educations: Fetch all educations.
  • GET /educations/{id}: Fetch an education by ID.
  • POST /educations: Create a new education.
  • PUT /educations/{id}: Update an education by ID.
  • DELETE /educations/{id}: Delete an education by ID.

Sample Request (using cURL)

  1. Fetch all educations:

    curl http://localhost:8081/educations
  2. Fetch a specific education by ID:

    curl http://localhost:8081/educations/1
  3. Create a new education:

    curl -X POST -H "Content-Type: application/json" -d '{"degree":"PhD","gpa":"3.5","student":{"firstname":"John","lastname":"Doe"}}' http://localhost:8081/educations
  4. Update an existing education:

    curl -X PUT -H "Content-Type: application/json" -d '{"degree":"Bachelor","gpa":"3.2","student":{"firstname":"Alice","lastname":"Smith"}}' http://localhost:8081/educations/1
  5. Delete an education:

    curl -X DELETE http://localhost:8081/educations/1

License

This project is licensed under the MIT License - see the LICENSE file for details.

go-crud-api's People

Contributors

leodeveloper avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.