Coder Social home page Coder Social logo

basemax / imagegalleryapigo Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 38 KB

This project is a Go-based RESTful API for managing an image gallery. Users can upload, view, update, and delete images with metadata. The API follows RESTful best practices, uses a database for storing metadata, and has clear documentation. Use it as a foundation for your own Go-based RESTful APIs.

License: GNU General Public License v3.0

Dockerfile 2.53% Go 97.47%
api go go-api golang golang-api restful restful-api

imagegalleryapigo's Introduction

Image Gallery API

This project is a RESTful API built with Go for managing an image gallery. It allows users to upload images, view a list of all images, view a single image, update image metadata, and delete images. The metadata for each image includes a title, description, and tags, and is stored in a database of your choice. The API follows best practices for RESTful API design, using appropriate HTTP methods and status codes and handling errors gracefully. The code is well-organized, modular, and readable, with clear documentation for the API endpoints. Use this project as a starting point for building your own Go-based RESTful APIs for image management.

Project

You will build a RESTful API that allows users to manage and view an image gallery. The API will allow users to upload images, view a list of all images, view a single image, update image metadata, and delete images. The metadata for each image will include a title, description, and tags.

Requirements

  • Use the net/http package to handle HTTP requests and responses.
  • Use a database of your choice to store image metadata.
  • Use the multipart/form-data content type to handle image uploads.
  • Implement the following endpoints:
    • POST /api/images: Upload a new image and its metadata.
    • GET /api/images: Retrieve a list of all images with their metadata.
    • GET /api/images/:id: Retrieve a single image with its metadata.
    • PUT /api/images/:id: Update the metadata for a single image.
    • DELETE /api/images/:id: Delete a single image.
  • Handle errors gracefully and provide appropriate HTTP status codes in responses.
  • Write clear and concise documentation for the API endpoints.
  • Use best practices for RESTful API design, including proper HTTP methods and status codes.

Endpoints

This API have the following endpoints:

  • GET /api/images/

Returns a JSON array of all images and it's metadata.

curl -s http://localhost:8080/api/images/ | jq

Response body:

[
  {
    "id": 1,
    "title": "My Image",
    "description": "This is my image",
    "tags": "tag1,tag2",
    "file_path": "uploads/1680919323489361965.png",
    "created_at": "2023-04-08 05:32:03"
  },
  {
    "id": 2,
    "title": "My Image",
    "description": "This is my image",
    "tags": "tag1,tag2",
    "file_path": "uploads/1680919362135848916.png",
    "created_at": "2023-04-08 05:32:42"
  },
  {
    "id": 3,
    "title": "My Image",
    "description": "This is my image",
    "tags": "tag1,tag2",
    "file_path": "uploads/1680919369929026576.png",
    "created_at": "2023-04-08 05:32:49"
  }
]
  • GET /api/images/{id:[1-9]+}

Returns the JSON representation of a single image and it's metadata specified by the id parameter.

curl -s http://localhost:8080/api/images/1 | jq

Response Body:

{
  "id": 1,
  "title": "My Image",
  "description": "This is my image",
  "tags": "tag1,tag2",
  "file_path": "uploads/1680919323489361965.png",
  "created_at": "2023-04-08 05:32:03"
}
  • POST /api/images/

Adds a new image with it's metadata.

Request command(curl):

curl -s -X POST -H "Content-Type: multipart/form-data" \
            -F "image=@/home/max/Pictures/golang/1.png" \
            -F "title=My Image" \
            -F "description=This is my image" \
            -F "tags=tag1,tag2" http://localhost:8080/api/images/ | jq

Response Body:

{
  "id": 1,
  "title": "My Image",
  "description": "This is my image",
  "tags": "tag1,tag2",
  "file_path": "uploads/1680919323489361965.png",
  "created_at": "2023-04-08 05:32:03"
}
  • PUT /api/images/{id:[1-9]+}

Updates an existing image metadata specified by the id parameter.

Request command(curl):

curl -X PUT -H "Content-Type: application/json" \
            -d '{"title":"New Title", "description":"New Description", "tags":"new, tags"}' \
            http://localhost:8080/api/images/1

Response Body:

{
  "id": 0,
  "title": "New Title",
  "description": "New Description",
  "tags": "new, tags",
  "file_path": "",
  "created_at": ""
}
  • DELETE /api/images/{id:[1-9]+}

Deletes an existing image and it's metadata specified by the id parameter.

curl -X DELETE http://localhost:8080/api/images/1

Response Body:

{
  "message": "Image with ID 1 has been deleted"
}

Evaluation

Your solution will be evaluated on the following criteria:

  • Does it implement all required endpoints with correct functionality?
  • Is the code well-organized, modular, and readable?
  • Is the error handling robust and informative?
  • Is the database schema well-designed and efficient?
  • Is the API documentation clear and concise?
  • Are best practices for RESTful API design followed?

Copyright, Max Base, MaxianEdison 2023

imagegalleryapigo's People

Contributors

maxianedison avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

imagegalleryapigo's Issues

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.